Discord.py在回应消息时发挥作用

时间:2020-05-25 02:18:34

标签: python-3.x discord discord.py

我无法使此代码正常工作,发布响应消息是没有问题的。但是,给具有“测试版”角色的用户是行不通的。

Discord.py版本:0.16.12

@bot.command(pass_context=True)
async def test(ctx):
    if ctx.message.author.server_permissions.administrator:
        testEmbed = discord.Embed(color = discord.Color.red())
        testEmbed.set_author(name='Test')
        testEmbed.add_field(name='Test', value='Test')

    msg = await bot.send_message(ctx.message.channel, embed=testEmbed)
    await bot.add_reaction(msg, emoji='✅')

@bot.event
async def on_reaction_add(reaction, user):
    Channel = bot.get_channel('714282896780951563')
    if reaction.message.channel.id != Channel:
        return
    if reaction.emoji == "✅":
        Role = discord.utils.get(user.server.roles, name="Beta")
        await bot.add_roles(user, Role)

1 个答案:

答案 0 :(得分:0)

reaction.message.channel.id != Channel

永远不会是True,因为Channeldiscord.Channel对象,而reaction.message.channel.id是字符串。

相反,您应该直接将ID与预期ID进行比较:

if reaction.message.channel.id != '714282896780951563':