简体   繁体   English

Python Discord 机器人 - 反应角色

[英]Python Discord Bot - Reaction Role

How would i make a reaction role event.我将如何制作反应角色事件。 This is my code i tried with这是我尝试过的代码

@client.event
async def on_raw_reaction_add(payload):
    msgID = 05793080854315018
    if payload != None:
        if payload.message_id == msgID:
            if str(payload.emoji) == "✍️":
                await add_roles("cool")

What i wanna do is have my bot checking for reactions on a specific message and then give the user a role if they reacted with the right emoji.我想做的是让我的机器人检查对特定消息的反应,然后如果用户对正确的表情符号做出反应,就给他们一个角色。

Assuming that you are using discord.py 1.3.3 you can update your code with the following to add a role based on a specific emoji.假设您使用的是discord.py 1.3.3 ,您可以使用以下代码更新您的代码,以添加基于特定表情符号的角色。

You need to add references to the guild in order to reference the role you wish to add.您需要添加对公会的引用才能引用您希望添加的角色。 You will also need to compare the emoji to a string representation of payload.emoji .您还需要将表情符号与payload.emoji的字符串表示进行比较。 It might be worth considering using emoji.demojize .可能值得考虑使用emoji.demojize

Try:尝试:

@client.event
async def on_raw_reaction_add(payload=None):
    msgID = <your message id: int>
    guild = discord.utils.get(client.guilds, name=<your guild name>)
    role = discord.utils.get(guild.roles, name='cool')
    if payload is not None:
        if payload.message_id == msgID:
            if str(payload.emoji) == "✍️":
                await payload.member.add_roles(role)

I refreshed your code, but it still not working, so if someone could help I'm also searching for a solution, first you import discord's library;我刷新了您的代码,但它仍然无法正常工作,所以如果有人可以帮助我也在寻找解决方案,首先您导入不和谐的库;

import discord
from discord.client import Client
from discord.ext import commands

#I also add a prefix if code would evolve later: #如果代码稍后会发展,我还会添加一个前缀:

bot = commands.Bot(command_prefix='!')

#Here we got a message who tells bot is online #这里我们收到一条消息,告诉机器人在线

@bot.event
async def on_ready():
    print("Bot Is entered the building!")

#Then here is the code; #那么这里是代码;

@bot.event
async def on_raw_reaction_add(payload=None):
    msgID = 9454546465646847898,
    guild = 7894651646646464898,
    role = discord.utils.get(guild.roles, name='lvl 0 Test bot')
    if payload is not None:
        if payload.message_id == msgID:
            if str(payload.emoji) == ":yes:":
                await payload.member.add_roles(role)


    bot.run("BOT TOKEN ID")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM