0

So I am making a discord bot and have a custom command that is ?plugins when I write that command I want it to send a msg with 4 reactions. If you react on the reaction 1 it will delete that embed and then send a new embed. And I want that with all the 4 reactions. I hope you understand, if not just tell me.

But Idk how to make this, I have tried a few things and looked on other people on stack overflow but I can't get it to work

I'm pretty new to programming and don't know that much xD But this is what I tried to do...

@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)
Sally
  • 23
  • 1
  • 11

1 Answers1

1

A few things to keep in mind working with discord emojis: You can't use :one: for reaction, you have to use unicode symbols. 1️⃣2️⃣3️⃣4️⃣

And for emojis in general, you can only add one at the time as a reaction, but you can create a for loop to add emojis from a list

I see you want the bot to delete the embed and then send a new one. How about editing the sent embed? Have a look in to the answer here.

Just to show you how to it with embeds I'm adding an edited version of the code here.

Change the embeds to what you need them to be.

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

To print your emojis in the terminal so you can copy them:

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

add as many emojis as you want, custom ones, discord ones.. it will print all of them in the terminal. custom ones shows up as <:emoji_name:emoji_id> (or <a:emoji_name:emoji_id> if animated)

AbdurJ
  • 997
  • 2
  • 6
  • 13
  • Wow thanks a lot! But the code didn't really work, I got a few problems... Like 34 problems. For example `` Unexpected indent Unresolved reference 'reaction' Unresolved reference 'emb_message' Unresolved reference 'embed_1' Unresolved reference 'user' And more... The problems start from ```python while True: try: reaction, user = await bot.wait_for("reaction_add", timeout=60, check=check) # timeout is how long this will work. after x it will no longer delete/change embed ``` Then it just keeps all the way down with more problems =/ – Sally Nov 05 '20 at 22:59
  • Sorry for how the text looks, I don't really know how Stack overflow works. Yeah I am like new to all this xD Started for a few weeks ago – Sally Nov 05 '20 at 23:02
  • You know the block comment I added. Remove that. Also check indentations for the lines. Every time `:` is added, the code expects to see indented line. – AbdurJ Nov 05 '20 at 23:05
  • Oh yeah I forgot to remove that block comment, But what does it mean when it says ``Shadows name 'user' from outer scope``? – Sally Nov 05 '20 at 23:14
  • @Sally `shadow name 'user' from outer scope` occurs when you have a global variable named 'user' as well. It's not an error, more of a warning to prevent bugs down the line. Still worth taking a closer look at. Look for any earlier reference for `user` in your code. I tried copying the code to a different bot than what I tested it in first, and it seems to be working for me. Did you test it by copy-pasting it as is? – AbdurJ Nov 05 '20 at 23:31
  • I did everything you said before, with remove block comment and indentations for the lines. The bot works fine now but I was just wondering bcz I had that warning but everything works. – Sally Nov 05 '20 at 23:37
  • @Sally Oh, all right! I thought for a second that you still had some other error or that it wasn't working as intended. But that's great if it's working then! You can accept an answer so that the question shows up as "resolved". That way it's easier to see that you have the answer you needed. :) – AbdurJ Nov 05 '20 at 23:44
  • I have one question, how do you copy the reaction into the script? When I try to just copy and paste it, I get :one: and not the symbol – Sally Nov 06 '20 at 15:38
  • @Sally When in discord, add a "\" before the emoji. it will change from showing the emoji to show `\:one:` but when you send it, it will show the unicode message. Another way to do it is to just make a command that takes your string and outputs it in the terminal.. editing my answer above to show this – AbdurJ Nov 06 '20 at 16:43