[英]Discord.py Reaction Roles
我正在制作一个反应角色频道,如果你用表情符号做出反应,它会给你相应的角色。 我在我的验证系统中使用了完全相同的代码,它运行良好。 但是由于某种原因,当我使用相应的表情符号对消息做出反应时,我没有得到角色,没有出现回溯,并且我没有在控制台中收到“给某人一个角色”的消息。
代码:
async def roles(ctx):
embed=discord.Embed(title="Reaction Roles", description="React with the corresponding emoji to get the role", color=0xff0000, timestamp=datetime.now())
embed.set_author(name="Official Gnag Discord", icon_url="https://upload.wikimedia.org/wikipedia/commons/thumb/2/2e/Exclamation_mark_red.png/50px-Exclamation_mark_red.png")
embed.add_field(name="⛓️", value="Role 1", inline=True)
embed.add_field(name="💩", value="Role 2", inline=True)
embed.add_field(name="💣", value="Role 3", inline=True)
embed.add_field(name="🏳️🌈", value="Role 4", inline=True)
embed.add_field(name="👧", value="Role 5", inline=True)
embed.add_field(name="🌈", value="Role 6", inline=True)
embed.add_field(name="🤡", value="Role 7", inline=True)
embed.add_field(name="✔️", value="Role 8", inline=True)
embed.add_field(name="🤓", value="Role 9", inline=True)
embed.add_field(name="🎥", value="Role 10", inline=True)
embed.add_field(name="♂️", value="Role 11", inline=True)
embed.set_footer(text="Official Gnag Discord Bot Made By @Lukeee#6032")
msg = await ctx.send(embed=embed)
await msg.add_reaction('🤡')
await msg.add_reaction('✔️')
await msg.add_reaction('🤓')
await msg.add_reaction('🎥')
await msg.add_reaction('♂️')
await msg.add_reaction('⛓️')
await msg.add_reaction('💩')
await msg.add_reaction('💣')
await msg.add_reaction('🏳️🌈')
await msg.add_reaction('👧')
await msg.add_reaction('🌈')
@bot.event
async def on_raw_reaction_add(payload):
ourMessageID = 819597141743763467
if ourMessageID == payload.message_id:
member = payload.member
guild = member.guild
emoji = payload.emoji.name
if emoji == '🤡':
mrole = discord.utils.get(guild.roles, name='Role 7')
await member.add_roles(mrole)
print ('gave a role to someone')
嘿,虽然你没有说你发出的是什么,但我想该命令不能正常工作。我建议你做这样的事情:
async def roles(ctx):
embed=discord.Embed(title="Reaction Roles", description="React with the corresponding emoji to get the role", color=0xff0000)
embed.set_author(name="Official Gnag Discord", icon_url="https://upload.wikimedia.org/wikipedia/commons/thumb/2/2e/Exclamation_mark_red.png/50px-Exclamation_mark_red.png")
embed.add_field(name="⛓️", value="Role 1", inline=True)
embed.add_field(name="💩", value="Role 2", inline=True)
embed.add_field(name="💣", value="Role 3", inline=True)
embed.add_field(name="🏳️🌈", value="Role 4", inline=True)
embed.add_field(name="👧", value="Role 5", inline=True)
embed.add_field(name="🌈", value="Role 6", inline=True)
embed.add_field(name="🤡", value="Role 7", inline=True)
embed.add_field(name="✔️", value="Role 8", inline=True)
embed.add_field(name="🤓", value="Role 9", inline=True)
embed.add_field(name="🎥", value="Role 10", inline=True)
embed.add_field(name="♂️", value="Role 11", inline=True)
embed.set_footer(text="Official Gnag Discord Bot Made By @Lukeee#6032")
msg = await ctx.send(embed=embed)
await msg.add_reaction('🤡')
await msg.add_reaction('✔️')
await msg.add_reaction('🤓')
await msg.add_reaction('🎥')
await msg.add_reaction('♂️')
await msg.add_reaction('⛓️')
await msg.add_reaction('💩')
await msg.add_reaction('💣')
await msg.add_reaction('🏳️🌈')
await msg.add_reaction('👧')
await msg.add_reaction('🌈')
def check(reaction, user):
return user == ctx.user and reaction.message == msg and str(reaction.emoji) in ['🤡','✔','🤓','🎥','♂','⛓','💩','💣','🏳️🌈','👧','🌈']
while True:
try:
reaction, user = await client.wait_for("reaction_add", check=check)
if str(reaction.emoji) == '🤡':
mrole = discord.utils.get(ctx.guild.roles, name='Role 7')
await user.add_roles(mrole)
print ('gave a role to someone')
Ps 复制粘贴前,请阅读。 它甚至可能不适合你。
编辑:您也可以加入 discord.py 服务器以获得更多帮助discord.py
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.