为什么我的discord机器人不使用discord.py重写连接到通道?

时间:2019-02-22 01:14:18

标签: python discord discord.py-rewrite

好的,所以我仍然对python和程序设计还很陌生,通常试图让我的不和谐机器人加入我的频道,但是当我键入命令时却没有加入。我尝试了几种不同的方法。这是代码:

@client.event
async def voice_chat(message, VoiceChannel):
    if message.content == "!join":
            musicplayer = VoiceChannel.connect()

我还尝试用客户端替换两个VoiceChannel,但仍然无法正常工作,如果尝试将message.content替换为await,但我也尝试将其替换,但没有任何尝试。有人知道这段代码有什么问题吗?

1 个答案:

答案 0 :(得分:0)

您需要使用commands.command()

@commands.command()
async def join(self, ctx, voice_channel):

然后使用voice_channel.connect()

voice_channel.connect()

我建议也使用VoiceChannelConverter。因此,您的所有函数看起来都应该像这样,减去您想要的任何其他逻辑。

from discord.ext import commands

@commands.command()
async def join(self, ctx, voice_channel: commands.VoiceChannelConverter):
    try:
        await voice_channel.connect()
    except commands.BotMissingPermissions as error:
        #send them a prettied up message saying HEY I NEED {} PERMS!
    await ctx.send(f"I have joined: {voice_channel}")

还请注意,该应该应该在cog / 扩展名之内,因此请考虑在内。至少这是正常习惯,类似于“语音”嵌齿轮。

相关问题