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.
Add a comment  | 

1 Answer 1

Reset to default 0

The 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()

本文标签: