Discord.py Discord py如何加入语音频道
如何让我的机器人(在cog中)加入用户所在的语音频道? 我有以下代码:Discord.py Discord py如何加入语音频道,discord.py,Discord.py,如何让我的机器人(在cog中)加入用户所在的语音频道? 我有以下代码: @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.clie
@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)
您需要使用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)
这应该可以使用您需要使用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)
这应该行得通非常感谢:)工作的NP,只需投票发布:)没有足够的声誉sry:/非常感谢:)工作的NP,只需投票发布:)没有足够的声誉sry:/