首页 > 解决方案 > Discord.py 反应角色和 DMing 反应堆

问题描述

我希望机器人给对消息做出反应的人一个角色。机器人还应该 dm 做出反应的人。先感谢您。

这是我的代码:

@client.event
async def on_raw_reaction_add(payload):
    
    if payload.emoji.name == "" and payload.user_id != client.user.id:
        embed = discord.Embed(
            description = "**You are now a Member of Resellheads!** ",
            color=16769251)
        
        channel = client.get_channel(payload.channel_id)
        message = await channel.fetch_message(payload.message_id)
        await message.channel.send(embed=embed)
        
        await message.channel.send("<@&776929011757613057> Please add the role 'Member'!")



标签: pythondiscorddiscord.py

解决方案


在您的情况下无需使用原始反应添加,因为您仅使用它来发送命令。

@client.event
async def on_reaction_add(reaction, user):
    
    if reaction.emoji == '':
        await user.send("You are now a member of your community!")

    if reaction.emoji == '':
        await user.send("Sad to see you leave")

这将简单地发送任何对您的命令/消息表示赞同或反对的用户。

在这种情况下,如果您的机器人是私人或小型机器人,这应该可以使用,但是变得更大并且在更多服务器中,您应该使用反应等待,等待作者发送命令后他指定的反应。您的问题中没有详细解释,但我希望这会有所帮助


推荐阅读