如果对反应有反应

时间:2020-11-05 18:36:00

标签: python bots discord.py

因此,我正在制作一个不和谐的bot,并有一个自定义命令?plugins,当我编写该命令时,我希望它发送带有4个响应的味精。如果您对反应1做出反应,它将删除该嵌入,然后发送新的嵌入。我希望所有这4个反应都可以。希望您能理解,即使不告诉我。

但是,Idk如何做到这一点,我尝试了一些尝试,并在堆栈溢出的情况下看着其他人,但是我无法使其工作

我对编程很陌生,对xD的了解也不多 但这是我试图做的...

@bot.command(name='plugins')
async def plugins(context):
    my_embed = discord.Embed(title='Welcometo to SteinerCraft plugin page!', color=0xFFC71C)
    my_embed.set_author(name='SC.B#4073', icon_url='https://cdn.discordapp.com/attachments/765665083082407976'
                                                   '/767456901398921246/SC.B_remix_profile.png')
    my_embed.add_field(name='Select what type of help you need.', value='.', inline=False)
    my_embed.add_field(name='Home => :one:', value='Friend => :two:', inline=True)
    my_embed.add_field(name='Community => :three:', value='Other => :four:', inline=True)
    await context.message.channel.send(embed=my_embed)
    await bot.add_reaction(':one:' and ':two:' and ':three:' and ':four:')

if reaction.emoji ==':one:':
    my_embed = discord.Embed(title="Home",
color=0xFFC71C)

elif reaction.emoji == ':two:':
    my_embed = discord.Embed(title="Friend", color=0xFFC71C)

1 个答案:

答案 0 :(得分:1)

使用不协调的表情符号时需要记住的几件事:不能使用:one来进行反应,必须使用unicode符号。 1️⃣2️⃣3️⃣4️⃣

对于一般的表情符号,您一次只能添加一个作为反应,但是您可以创建一个for循环以从列表中添加表情符号

我看到您希望漫游器删除嵌入内容,然后发送新的嵌入内容。如何编辑已发送的嵌入?看看答案here

只是为了向您展示如何嵌入,我在这里添加了代码的编辑版本。

将嵌入更改为所需的嵌入。

import asyncio

@bot.command(name='plugins')
async def plugins(ctx):
    message = ctx.message
    embed_1 = discord.Embed(title='Welcometo to SteinerCraft plugin page!', color=0xFFC71C)
    embed_1.set_author(name='SC.B#4073', icon_url='https://cdn.discordapp.com/attachments/765665083082407976/767456901398921246/SC.B_remix_profile.png')
    embed_1.add_field(name='Select what type of help you need.', value='.', inline=False)
    embed_1.add_field(name='Home => :one:', value='Friend => :two:', inline=True)
    embed_1.add_field(name='Community => :three:', value='Other => :four:', inline=True)

    embed_2 = discord.Embed(title='A second embed page', color=0xFFC71C)
    embed_2.set_author(name='SC.B#4073', icon_url='https://cdn.discordapp.com/attachments/765665083082407976/767456901398921246/SC.B_remix_profile.png')
    embed_2.add_field(name='Select what type of help you need.', value='.', inline=False)
    embed_2.add_field(name='Home => :one:', value='Friend => :two:', inline=True)
    embed_2.add_field(name='Community => :three:', value='Other => :four:', inline=True) 

    embed_3 = discord.Embed(title='A third embed page', color=0xFFC71C)
    embed_3.set_author(name='SC.B#4073', icon_url='https://cdn.discordapp.com/attachments/765665083082407976/767456901398921246/SC.B_remix_profile.png')
    embed_3.add_field(name='Select what type of help you need.', value='.', inline=False)
    embed_3.add_field(name='Home => :one:', value='Friend => :two:', inline=True)
    embed_3.add_field(name='Community => :three:', value='Other => :four:', inline=True)

    embed_4 = discord.Embed(title='A fourth embed page', color=0xFFC71C)
    embed_4.set_author(name='SC.B#4073', icon_url='https://cdn.discordapp.com/attachments/765665083082407976/767456901398921246/SC.B_remix_profile.png')
    embed_4.add_field(name='Select what type of help you need.', value='.', inline=False)
    embed_4.add_field(name='Home => :one:', value='Friend => :two:', inline=True)
    embed_4.add_field(name='Community => :three:', value='Other => :four:', inline=True)

    emb_message = await ctx.message.channel.send(embed=embed_1)
    emoji_list = ['1️⃣','2️⃣','3️⃣','4️⃣']
    for i in emoji_list:
        await emb_message.add_reaction(i)

    def check(reaction, user):
        return user == ctx.author and str(reaction.emoji) in emoji_list
        # This makes sure nobody except the command sender can interact

    while True:
        try:
            reaction, user = await bot.wait_for("reaction_add", timeout=60, check=check)

            if str(reaction.emoji) == "1️⃣":
                await emb_message.edit(embed = embed_1)
                await emb_message.remove_reaction(reaction, user)

            elif str(reaction.emoji) == "2️⃣":
                await emb_message.edit(embed = embed_2)
                await emb_message.remove_reaction(reaction, user)
            
            elif str(reaction.emoji) == "3️⃣":
                await emb_message.edit(embed = embed_3)
                await emb_message.remove_reaction(reaction, user)

            elif str(reaction.emoji) == "4️⃣":
                # await emb_message.edit(embed = embed_4)
                await emb_message.remove_reaction(reaction, user)
                
            else:
                await message.remove_reaction(reaction, user)
        except asyncio.TimeoutError:
            break
            # ending the loop if user doesn't react after x seconds

要在终端上打印表情符号,以便您可以复制它们:

@bot.command()
async def emojiprint(ctx, *, emojis):
    print(emojis)

根据需要添加任意多个表情符号,自定义表情符号,不和谐表情符号..它将在终端中打印所有表情符号。自定义项显示为<:emoji_name:emoji_id>(如果已设置动画,则显示为