Hey folks, I’m working on a Discord bot and I’m stuck. I want to make it so users can only add a thumbs up
after they’ve added a leg
. Right now, my code just lets them use either one:
@bot.event
async def on_emoji_added(emoji, member):
if bot.user == member:
return
if member != emoji.message.author and emoji.icon not in ('🦵', '👍'):
await emoji.delete(member)
I tried using asyncio but it didn’t work. I’m not sure how to check if the first emoji is there before allowing the second one. Can anyone help? I’m pretty tired and my brain’s fried.
Also, I tried to log when emojis are removed, but it’s not working:
@bot.event
async def on_emoji_removed(emoji, member):
if bot.user == member:
return
print('Emoji removed')
if member and (emoji.icon) in ('🦵', '👍'):
chat = bot.get_chat(9876543210987654321)
print('Sending message')
await chat.send(f'{member.name} removed {emoji.icon}')
It’s not even hitting the first print statement. Any ideas what I’m doing wrong? Thanks!
hey, for the emoji thing, maybe try using a list to keep track? like this:
user_reactions =
@bot.event
async def on_reaction_add(reaction, user):
if user == bot.user:
return
if str(reaction.emoji) == '🦵':
user_reactions.append(user.id)
elif str(reaction.emoji) == '👍' and user.id not in user_reactions:
await reaction.remove(user)
might work? dunno bout the removal stuff tho, sorry
I’ve faced similar challenges with Discord bots before. For the sequencing issue, you might want to consider using a dictionary to track user reactions. Something like:
user_reactions = {}
@bot.event
async def on_reaction_add(reaction, user):
if user == bot.user:
return
if str(reaction.emoji) == '🦵':
user_reactions[user.id] = True
elif str(reaction.emoji) == '👍':
if user.id not in user_reactions or not user_reactions[user.id]:
await reaction.remove(user)
else:
user_reactions[user.id] = False
This way, you’re keeping track of who’s reacted with the leg emoji before allowing the thumbs up.
As for the emoji removal logging, the event you’re looking for is on_reaction_remove, not on_emoji_removed. Try this:
@bot.event
async def on_reaction_remove(reaction, user):
if user == bot.user:
return
print('Emoji removed')
if str(reaction.emoji) in ('🦵', '👍'):
channel = bot.get_channel(9876543210987654321)
await channel.send(f'{user.name} removed {reaction.emoji}')
Hope this helps! Let me know if you need any clarification.
For the sequencing issue, consider using a database or a persistent storage solution to track user reactions across sessions. This approach is more robust than in-memory dictionaries, especially if your bot restarts frequently.
Regarding the emoji removal logging, the event you’re looking for is indeed ‘on_reaction_remove’. However, make sure you have the necessary intents enabled for your bot to receive these events. You might need to add:
bot.intents.reactions = True
in your bot initialization.
Also, double-check your channel ID. If it’s incorrect, your messages won’t be sent. You can use:
channel = reaction.message.channel
to get the channel where the reaction was removed, eliminating potential ID errors.
Lastly, remember to handle exceptions. Network issues or API rate limits can cause unexpected behavior.