discord.py 反应获得角色
discord.py react to get role
我将这个带有规则的嵌入到我的 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)
我将这个带有规则的嵌入到我的 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)