admin管理员组文章数量:1221376
I am using discord.py with the default app_commands
from discord import Intents, Client, Message, app_commands
from discord.voice_client import VoiceClient
@treemand(
name="play",
description="insert a youtube url for music",
guild = discord.Object(id=806555220468432906)
)
async def play_command(command) -> None:
source = discord.PCMVolumeTransformer(discord.FFmpegPCMAudio("Music.m4a"))
VoiceClient.play(source)`
This code produces the error:
TypeError: VoiceClient.play() missing 1 required positional argument: 'source'
I've tried changing the encoding of FFmpeg while still getting the same error. help
I am using discord.py with the default app_commands
from discord import Intents, Client, Message, app_commands
from discord.voice_client import VoiceClient
@tree.command(
name="play",
description="insert a youtube url for music",
guild = discord.Object(id=806555220468432906)
)
async def play_command(command) -> None:
source = discord.PCMVolumeTransformer(discord.FFmpegPCMAudio("Music.m4a"))
VoiceClient.play(source)`
This code produces the error:
TypeError: VoiceClient.play() missing 1 required positional argument: 'source'
I've tried changing the encoding of FFmpeg while still getting the same error. help
Share Improve this question asked 2 days ago Nick_27Nick_27 113 bronze badges New contributor Nick_27 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.1 Answer
Reset to default 0The play()
method should be called on an instance of VoiceClient
rather than the class itself.
Here is a possible fix, which gets a VoiceClient by connecting to the voice channel the user who ran the command is in (in reality you should verify whether the user is in any voice channel at all and check whether the bot is already in a VC):
@tree.command(
name="play",
description="insert a youtube url for music",
guild=discord.Object(id=806555220468432906)
)
async def play_command(command: discord.Interaction) -> None:
source = discord.PCMVolumeTransformer(discord.FFmpegPCMAudio("Music.m4a"))
voice_channel = command.user.voice.channel
voice_client = await voice_channel.connect()
voice_client.play(source)
await voice_client.disconnect()
本文标签:
版权声明:本文标题:python - VoiceClient.play() missing 1 required positional argument: 'source' error when trying to play audio in 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739260917a2155362.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论