Discord.py 我的join命令在移动到cog文件后中断,我找不到如何修复它 @commands.command(name=“join”) 异步def联接(自、ctx): 频道=ctx.author.voice.channel voice=discord.utils.get(self.voice\u客户端,guild=ctx.guild) 如果voice和voice.is_已连接(): 等待语音。移动到(频道) 其他: 语音=等待频道。连接()

Discord.py 我的join命令在移动到cog文件后中断,我找不到如何修复它 @commands.command(name=“join”) 异步def联接(自、ctx): 频道=ctx.author.voice.channel voice=discord.utils.get(self.voice\u客户端,guild=ctx.guild) 如果voice和voice.is_已连接(): 等待语音。移动到(频道) 其他: 语音=等待频道。连接(),discord.py,Discord.py,这是因为通过使用self.voice\u客户端您试图获取cog的通道,而不是机器人的通道。尝试这样做: 在\uuuu init\uuuu中定义self.bot如下: def\uuuu初始化(self,bot): self.bot=bot 在命令replace中: discord.utils.get(self.voice\u客户端,guild=ctx.guild) 与: discord.utils.get(self.bot.voice\u客户端,guild=ctx.guild) 顺便说一句,获

这是因为通过使用
self.voice\u客户端
您试图获取cog的通道,而不是机器人的通道。尝试这样做: 在
\uuuu init\uuuu
中定义
self.bot
如下:

def\uuuu初始化(self,bot):
self.bot=bot
在命令replace中:

discord.utils.get(self.voice\u客户端,guild=ctx.guild)
与:

discord.utils.get(self.bot.voice\u客户端,guild=ctx.guild)

顺便说一句,获取语音客户端的一种更简单的方法是
ctx.voice\u client
。是的,但我希望尽可能靠近提供的代码。知道了,这很有效,我真的很高兴stackoverflow的存在!