问题
await message.add_reaction('📜')
await message.add_reaction('🔧')
await message.add_reaction('🔨')
await message.add_reaction('🔥')
message = await client.wait_for('on_reaction_add', timeout= 10, check=lambda message: message.author == ctx.author)
if message.reaction_add == '📜':
await ctx.send("You reacted!")
Im making a command to use the help page and it edits the pre-existing help message to the category the user chooses that corresponds to the emoji they reacted for.
I have used a way that has no checks which annoys other people if they happen to react with those emojis to another message, is there are way to make a check similar to what I have already done or close to, where the message of help can be edited to the page the user wants and only works if they used the command specifically for the author that can use the emojis?
Please let me know soon thanks! Its annoying some people that have invited the bot
回答1:
To condense this a little bit, I will use only two of the provided reactions.
@client.command()
async def test(ctx):
message = await ctx.send("Message that's getting reactions")
paper = '📜' # for the sake of "I'd rather not copy and paste these emojis a lot"
hammer = '🔨'
await message.add_reaction(paper)
await message.add_reaction(hammer)
def check(reaction, user):#checking for reactions and user
return user == ctx.author and str(reaction.emoji) in [paper, hammer]
# in this case, the message author and the reaction emojis paper and hammer
try:
reaction, user = await client.wait_for("reaction_add", timeout = 3, check=check)
# waiting for a reaction to be added
if str(reaction.emoji) == paper:
await ctx.send("You reacted!")
if str(reaction.emoji) == hammer:
await message.edit(content="Another reaction!")# this is for editing the message sent
except: # Timeout error-handling
await message.edit(content="Run command to use again!")
If you'd like, you could also include while True
so the user doesn't have to constantly execute the command.
Working test as seen in the image below:
References:
discord.Client.wait_for
discord.Message.edit
How to loop with a reaction embed menu (SO)
回答2:
reaction, user = await client.wait_for('reaction_add', timeout=10.0, check...)
If you read the docs about on_reaction_add
, you'll see that it takes reaction
and user
arguments.
To edit the message:
message = reaction.message
await message.edit(content='new content!')
来源:https://stackoverflow.com/questions/65252200/how-can-i-check-for-a-reaction-for-my-help-command-in-d-py-which-checks-the-that