Bots discord.py响应以获取角色

Bots discord.py响应以获取角色,bots,discord.py,roles,Bots,Discord.py,Roles,我有这个嵌入规则到我的discord服务器,嵌入也有一个反应,反应是一个复选标记(✅). 如果您使用该复选标记对嵌入做出反应,您将获得一个“验证”角色,您的反应将被删除 所以这总是一个反应,如果你做出反应,你会得到“验证”角色,你的反应会被删除。 但这就是问题所在,当我做出反应时,我没有得到我的角色,我的反应也没有被删除。我没有任何错误,我不知道如何解决这个问题 这是我的密码 @bot.command(name='rules', pass_ctx=True) async def rules(ct

我有这个嵌入规则到我的discord服务器,嵌入也有一个反应,反应是一个复选标记(✅). 如果您使用该复选标记对嵌入做出反应,您将获得一个“验证”角色,您的反应将被删除

所以这总是一个反应,如果你做出反应,你会得到“验证”角色,你的反应会被删除。 但这就是问题所在,当我做出反应时,我没有得到我的角色,我的反应也没有被删除。我没有任何错误,我不知道如何解决这个问题

这是我的密码

@bot.command(name='rules', pass_ctx=True)
async def rules(ctx):

    rules_embed = discord.Embed(title='DISCORD RULES', color=0xf30000)
    rules_embed.add_field(name="**1. No spamming** ", value="Don't send a lot of small/big messages right after "
                                                            "each other. Do not disrupt chat by spamming.",
                          inline=False)
    rules_embed.add_field(name="**2. No NSFW material** ", value="This is a community server and not meant to "
                                                                 "share this kind of material.", inline=False)
    rules_embed.add_field(name="**3. No bullying or threats** ", value="Threats to other users of DDoS(Distributed "
                                                                       "Denial of Service), Death, DoX/Doxx, abuse, "
                                                                       "and other "
                                                                       "malicious threats are absolutely not okay.",
                          inline=False)
    rules_embed.add_field(name="**4. Don't beg for ranks** ", value="Don't beg for staff or other ranks", inline=False)
    rules_embed.add_field(name="**5. No racism** ", value="Racism is absolutely not okay in this discord server",
                          inline=False)
    rules_embed.add_field(name="**6. Have fun** ", value="Just have fun and be nice", inline=False)

    send_rules = await ctx.message.channel.send(embed=rules_embed)
    reactions = ['✅']
    for i in reactions:
        await send_rules.add_reaction(i)


@bot.event
async def on_raw_reaction_add(payload):
    channel = bot.get_channel(payload.channel_id)
    message = await channel.fetch_message(payload.message_id)
    guild = bot.get_guild(payload.guild_id)
    reaction = discord.utils.get(message.reactions, emoji=payload.emoji.name)

    # only work if it is the client
    if payload.member.id == bot.user.id:
        return

    if payload.message_id == 784182764009947177 and reaction.emoji == '✅':
        roles = discord.utils.get(guild.roles, name='Verify')
        await payload.member.add_roles(roles)
        await reaction.remove(payload.member)

谢谢您的帮助!

您的代码中有几个错误,我已经修复了它们并对其中的一些进行了注释。请检查以下代码

@bot.event
async def on_raw_reaction_add(payload):
    #You forgot to await the bot.get_channel
    channel = await bot.get_channel(payload.channel_id)
    message = await channel.fetch_message(payload.message_id)
    guild = bot.get_guild(payload.guild_id)
    #Put the following Line
    member = guild.get_member(payload.user_id)
    reaction = discord.utils.get(message.reactions, emoji=payload.emoji.name)

    # only work if it is the client
    if payload.user_id == bot.user.id:
        return

    if payload.message_id == 784182764009947177 and reaction.emoji == '✅':
        roles = discord.utils.get(guild.roles, name='Verify')
        await member.add_roles(roles)
        await reaction.remove(payload.member)

您启用了什么意图?我有
intents=discord.intents.default()
intents.members=True
就是这个问题吗?我尝试了您发送的代码,但没有成功,我收到了一些错误。这些是错误“`File”C:/Users/Admin/PycharmProjects/Rosy.Dc.py/main.py”,第97行,在on_raw_reaction_add channel=wait bot.get_channel(payload.channel_id)中TypeError:object TextChannel在处理上述异常期间无法在“wait”表达式中使用,发生了另一个异常:``从bot.get_通道中删除wait并重试。哦,对不起,我本应该通过错误阅读,但非常感谢您的帮助,它现在可以工作了!