【问题标题】:why isn't my discord bot connecting to the channel with discord.py rewritten?为什么我的 discord 机器人没有用 discord.py 重写连接到频道?
【发布时间】:2019-07-16 01:11:02
【问题描述】:

好的,所以我对 python 和编程仍然很陌生,一般来说,试图让我的不和谐机器人加入我的频道,但是当我输入命令时它没有加入。我尝试了几种不同的方法。这是代码:

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

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

【问题讨论】:

    标签: python discord discord.py-rewrite


    【解决方案1】:

    你需要使用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/扩展中,所以要考虑到这一点。至少这是正常的约定,类似于“语音”齿轮。

    【讨论】:

      猜你喜欢
      • 2021-04-21
      • 1970-01-01
      • 2021-12-26
      • 2017-09-16
      • 2021-11-19
      • 2023-03-14
      • 2022-01-23
      • 1970-01-01
      • 2018-12-05
      相关资源
      最近更新 更多