我怎样才能让我的机器人(在一个齿轮中)加入用户所在的语音频道? 我有这个代码:
@commands.command(name='join')
async def join(self, ctx):
channel = ctx.author.channel
voice = discord.utils.get(ctx.guild.voice_channels, name=channel.name)
voice_client = discord.utils.get(self.client.voice_clients, guild=ctx.guild)
if voice_client == None:
await voice.connect()
else:
await voice_client.move_to(channel)
答案 0 :(得分:2)
您需要使用 ctx.author.voice.channel 而不是 ctx.author.channel
@commands.command(name='join')
async def join(self, ctx):
channel = ctx.message.author.voice.channel
voice = discord.utils.get(ctx.guild.voice_channels, name=channel.name)
voice_client = discord.utils.get(self.client.voice_clients, guild=ctx.guild)
if voice_client == None:
await voice.connect()
else:
await voice_client.move_to(channel)
这应该有效