📌  相关文章
📜  如何从具有反应不和谐机器人python代码示例的人中删除角色

📅  最后修改于: 2022-03-11 14:45:29.956000             🧑  作者: Mango

代码示例1
#you have to edit some parts of this code
import discord

#this is just another way to say @client.event 
class MyClient(discord.Client):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.target_message_id = (Your message id)

    async def on_ready(self):
        print('Running...')
    #Reaction added
    async def on_raw_reaction_add(self, payload):


        if payload.message_id != self.target_message_id:
            return

        guild = client.get_guild(payload.guild_id)


        if payload.emoji.name == '(Your emoji)':
            role = discord.utils.get(guild.roles, name='')
            await payload.member.add_roles(role)

    #Reaction removed
    async def on_raw_reaction_remove(self, payload):


        if payload.message_id != self.target_message_id:
            return

        guild = client.get_guild(payload.guild_id)
        member = guild.get_member(payload.user_id)


        if payload.emoji.name == '(Your emoji)':
            role = discord.utils.get(guild.roles, name='')
            await member.remove_roles(role)


intents = discord.Intents.default()
intents.members = True

client = MyClient(intents=intents)
client.run('')
#give this a thumbs up if it helped you