Bot 连接到语音通道,但我收到错误消息,说它未连接?

时间:2021-03-27 15:57:56

标签: discord.py

我遇到了一个奇怪的问题,机器人连接到语音通道,但后来我收到错误消息,说它没有连接?我在 github 上找到了这个,我用它作为基础 https://github.com/Rapptz/discord.py/blob/master/examples/basic_voice.py 昨天它工作得很好,但今天它坏了。我收到一个 channel = ctx.message.author.voice.channel 抛出的异常,说 'NoneType' 对象没有属性 'channel' 尽管将其更改为仅 channel = ctx.author.voice.channel 似乎可以解决问题?我也遇到了 ctx.voice_client.play(player, after=lambda e: print('Player error: %s' % e) if e else None) 说未连接到语音的问题。即使它是。

#Join Command
   @commands.command()
    async def join(self,ctx):
        channel = ctx.message.author.voice.channel
        if not channel:
            await ctx.send("You are not connected to a voice channel")
            return
        voice = discord.utils.get(self.client.voice_clients, guild=ctx.guild)
        if voice and voice.is_connected():
            await voice.move_to(channel)
        else:
            voice = await channel.connect()
        await voice.disconnect()
        if voice and voice.is_connected():
            await voice.move_to(channel)
        else:
            voice = await channel.connect()
        await ctx.send(f"Joined {channel}")
#Player Command
    @commands.command()
    async def play(self,ctx,*,url):
        async with ctx.typing():
            player = await YTDLSource.from_url(url, loop=self.client.loop)
            ctx.voice_client.play(player, after=lambda e: print('Player error: %s' % e) if e else None)

        await ctx.send('Now playing: {}'.format(player.title))
        await ctx.message.add_reaction("?") #testing reactions

0 个答案:

没有答案