音乐机器人未检测到用户在语音通道中

时间:2021-02-25 12:24:05

标签: python-3.x discord.py

我有一个名为“Potato Music”的音乐机器人,它是一个音乐机器人。目前,机器人按照我希望的方式执行命令。但是,一旦我停止在本地托管机器人并将其部署在 Heroku 上,就会出现一些错误。

我有一个名为“播放”的命令,当我执行该命令时,它应该在语音频道上播放一首歌曲。 play 命令在命令的开头有一个条件,用于检查用户是否已经在语音通道中。但是在我在 Heroku 上托管机器人后,一旦我执行 play 命令,它一直告诉我我没有连接到语音频道。

这是为什么?

这是我用来检查用户是否在语音频道中的代码:

@commands.command(pass_context=True)
async def play(self, ctx, *, song):
    # Detect if the user is already in a voice channel
    try:
        channel = ctx.author.voice.channel
        await channel.connect()    
    except Exception:
        pass
    
    voice = get(self.bot.voice_clients, guild=ctx.guild)
    
    # If the user is not connected in the voice channel...
    if not voice or not voice.is_connected():
        embed = discord.Embed(description='You should be connected to a voice channel to use the `p!play` command.', color=discord.Color.red())

        await ctx.send(embed=embed)
        return
    
    ... # The rest of the "play" command code

1 个答案:

答案 0 :(得分:0)

replace if not voice or not voice.is_connected(): to if not ctx.author.voice or not ctx.author.voice.channel:

不确定它是否适用于 Heroku...