【发布时间】:2020-11-25 22:53:31
【问题描述】:
我正在尝试创建一个命令,当用户对消息做出反应时,该命令本质上会赋予他们一个角色。我尝试了一些代码,但是当我运行机器人并对预先发送的消息做出反应时,没有发生错误,也没有任何反应。代码如下:
@client.command()
@commands.guild_only()
async def reactionrole(ctx, emoji, *, role):
roleEmbed = discord.Embed(title='Reaction Roles', description='React to this message with the proper emoji to give yourself the role.', color=discord.Colour.from_rgb(255, 107, 33))
roleEmbed.add_field(name='Roles & Emojis:', value=f'{emoji} = {role}', inline=True)
message = await ctx.send(embed=roleEmbed)
await message.add_reaction(f'{emoji}')
@client.event
async def on_reaction_add(reaction, user):
Channel = client.get_channel('my id')
if reaction.message.channel.id != Channel:
return
if reaction.emoji == "{emoji}":
Role = discord.utils.get(user.server.roles, name="event pings")
await client.add_roles(user, Role)
【问题讨论】:
标签: python-3.x discord discord.py