首页 > 解决方案 > 我如何制作一个机器人,如果你做出反应,它将赋予 ua 与 python 的角色?

问题描述

所以,我一直在这样做:

from discord.ext import commands
from discord.utils import get


client = commands.Bot(command_prefix='><')


@client.event
async def on_ready():
    print("I am ready Winson or not Winson :D")

@client.event
async def on_member_join(member):
    channel = client.get_channel(744440768667844698)
    message = await channel.send(f"Welcome to HaveNoFaith {member}, happy to be friends with you")

@client.command()
async def ping(ctx):
     await ctx.send(f"Your Ping is {round(client.latency *1000)}ms")

@client.command()
async def Help(ctx2):
    await ctx2.send("Hi, Im WelcomeBot v1.0...\n\nPrefix: ><\n\nCommands: ping\n          help")

#然后我尝试在“欢迎等”消息中做类似的事情,如果他们对该消息中的“检查反应”做出反应,他们将在不和谐服务器中获得一个角色......

标签: pythonpython-3.xpython-2.7discorddiscord.py

解决方案


您可以创建一个名为addrr(添加反应角色)的命令,如下所示 -

@client.command()
@commands.guild_only()
@commands.has_permissions(administrator=True)
    async def addrr(self, ctx, channel: discord.TextChannel, message: discord.Message, emoji: discord.Emoji,
                    role: discord.Role):
        await ctx.send(f"Setting up the reaction roles in {channel.mention}.")
        await message.add_reaction(emoji)

        def check1(reaction, user):
            return user.id is not self.client.user.id and str(reaction.emoji) in [f"{emoji}"]

        while True:
            try:
                reaction, user = await self.client.wait_for("reaction_add", check=check1)
                if str(reaction.emoji) == f"{emoji}":
                    await user.add_roles(role)
                    await message.remove_reaction(reaction, user)
                else:
                    await message.remove_reaction(reaction, user)
            except:
                await message.delete()
                break

它会像这样工作 -

><addrr <#channel mention> <message ID> <Emoji> <@Role Mention>


推荐阅读