我如何制作一个机器人,如果您做出反应,它将赋予您python的作用?

时间:2020-08-16 07:57:56

标签: python python-3.x python-2.7 discord discord.py

所以,我一直在这样做:

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")

#,然后我尝试在消息“ Welcome etc”中执行类似操作,如果他们对该消息中的“检查反应”做出反应,那么他们将在不和谐的服务器中扮演角色...

2 个答案:

答案 0 :(得分:0)

您可以创建一个名为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>

答案 1 :(得分:-1)

因此,您可以在已发送的消息中添加反应,并使用wait_for等待对该消息的反应。我建议您添加超时。如果您不希望超时,只需发送这些消息,将其保存到列表中,然后在raw_reaction_add event中检查表情符号是否是该表情符号,而该消息是否是列表中的消息之一

相关问题