'discord.py how to check if user react with special emoji on message
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)
Solution 1:[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)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
