【问题标题】:The bot does not give out a role when you click on the reaction, there are no errors, how to fix it?当你点击反应时,机器人没有给出角色,没有错误,如何解决?
【发布时间】:2021-05-16 19:15:49
【问题描述】:

一天中的好时光,创建了一条消息并添加了一个反应,但是当您单击它时,没有发出角色。 代码:

@commands.command(aliases = ["меропртиятие"])
@commands.has_permissions(administrator=True)
async def mp(self, ctx):
    emb = discord.Embed(title=f'Праздник ', description='Нажми на реакцию что бы получить роль',
                        colour=discord.Color.purple())

    message = await ctx.send(embed=emb)  
    await message.add_reaction('✅') 

    roles = discord.utils.get(message.guild.roles, id=839599224000610344) 

    check = lambda reaction, user: client.user != user 

    while True:
        reaction, user = await client.wait_for('reaction_add', check=check) 
        if str(reaction.emoji) == "✅":
            await user.add_roles(roles) 
            print('[SUCCESS] Пользователь {0.display_name} получил новую роль {1.name}'.format(user, roles)) 

            await user.send('TEST')

【问题讨论】:

  • 看起来像我为您的其他问题所做的答案...正如您的 other question 的 cmets 中所述,尝试将 Intent 添加到您的代码中,检查机器人角色是否高于您的角色想分配等等。

标签: python discord.py bots


【解决方案1】:

您应该为此使用on_reaction_add 事件。将嵌入的消息 id 存储在数据库或文件中,然后检查反应添加的消息 id 是否与存储的 message_id 相同。一个例子是:

async def on_reaction_add(self, reaction, user):
    message_id = reaction.message.id
    if str(reaction.emoji) == "✅" and message_id == STOREDMESSAGEID:
        # the rest of the code

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-13
    • 2020-04-22
    • 2020-11-21
    • 2020-12-05
    • 1970-01-01
    • 2022-11-27
    • 1970-01-01
    相关资源
    最近更新 更多