I'm working on a small 2-player game for my discord bot, And part of what the bot does is to react to its own message with some emojis as options
I want the bot to remove the user's reaction as soon as they react with the emoji, but message.reaction.remove
or message.remove_reaction
do not seem to work for me, here's some example code in case this was not clear:
import numpy as np
import discord
player1 = message.author #the user who starts the game with a command
player2 = message.mentions[0] #the first user who gets mentioned in the command
nums = ["1️⃣","2️⃣","3️⃣","4️⃣","5️⃣","6️⃣","7️⃣"]
The_Board = await message.channel.send(#The message that the bot will react to with nums)
while not game_over:
try:
reaction, confirmation = await client.wait_for("reaction_add",check=check)
turn = 0
if turn == 0:
Reaction_Turn = player1
elif turn == 1:
Reaction_Turn = player2
if Reaction_Turn == player1 and str(reaction.emoji) == "1️⃣":
colnum = 0
elif Reaction_Turn == player1 and str(reaction.emoji) == "2️⃣":
colnum = 1
#repetitive code for 7 emojis
#do stuff here
for i in nums:
await message.remove_reaction(i,Reaction_Turn)
After some trial and error, I finally got the remove_reaction method working, if you want to use this method under on_message
, try using try/except
for the method:
try:
message = The_Board
user = Reaction_Turn
for x in nums:
await message.remove_reaction(x,user)
except:
pass
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.