我所做的反应角色命令发送消息并添加角色,但是当有人单击它时,它什么也没做,并且我的终端中没有任何错误。有人可以帮我吗?
@client.command(description="Use reactions to give people roles.", aliases=['rr', 'reactionrole'])
async def reactrole(ctx, emoji, role : discord.Role, *, message):
message = await ctx.send(message)
await message.add_reaction(emoji)
with open('reactrole.json') as json_file:
data = json.load(json_file)
new_react_role = {
'role_name':role.name,
'role_id':role.id,
'emoji':emoji,
'message_id':message.id
}
data.append(new_react_role)
with open('reactrole.json', 'w') as j:
json.dump(data, j, indent=4)
@client.event
async def on_raw_reaction_add(payload):
if payload.member.bot:
pass
else:
with open('reactrole.json') as react_file:
data = json.load(react_file)
for x in data:
if x['emoji'] == payload.emoji.name and x['message_id'] == payload.message_id:
role = discord.utils.get(client.get_guild(payload.guild_id).roles, id=x['role_id'])
await payload.member.add_roles(role)
答案 0 :(得分:0)
您需要启用 discord.Intents.reactions
。这可以通过在 client
对象的声明中设置此属性来实现。
intents = discord.Intents.default()
intents.reactions = True
client = discord.Client(intents = intents)