Discord bot problem“是缺少的必需参数”

2024-10-01 07:46:34 发布

您现在位置:Python中文网/ 问答频道 /正文

所以基本上我正在尝试制作一个youtube播放器命令,它可以通过语音聊天播放音频,我一直在测试这个命令,它一直在说“disfunctional(变量名)是一个缺少的必要参数”,我提供了这个链接,但它仍然说它丢失了,我可能只是哑巴,但我几乎肯定这应该是有效的

@client.command(pass_context=True)
async def yt(self, ctx,*, dysfunctional):
    channel = ctx.message.author.voice.voice_channel
    if dysfunctional.startswith('https://www.youtube.com'):
        voice = await client.join_voice_channel(channel)
        player = await voice.create_ytdl_player(dysfunctional)
        player.start()
    if dysfunctional == "stop":
        player.stop()
        disconnect()

Tags: 命令clientifyoutubechannel语音await音频
1条回答
网友
1楼 · 发布于 2024-10-01 07:46:34

您不在cog类中,因此无法获取self参数。尝试使用以下代码

@client.command(pass_context=True)
async def yt(ctx, *, dysfunctional):
    channel = ctx.message.author.voice.voice_channel
    if dysfunctional.startswith('https://www.youtube.com'):
        voice = await client.join_voice_channel(channel)
        player = await voice.create_ytdl_player(dysfunctional)
        player.start()
    if dysfunctional == "stop":
        player.stop()
        disconnect()

相关问题 更多 >