问题
Something like this.
@client.event
async def on_reaction_add(reaction, user):
a = await client.say("React to see help")
if reaction.emoji == "😃":
await client.edit_message(a, "Moderator commands")
Here's an example: https://cdn.discordapp.com/attachments/562005351353024525/569931890577113098/unknown.png But I want the bot to edit the first message. Can someone help?
回答1:
You need to send a message when the bot comes online, then monitor that message for new reactions. The easiest way to do that is with a background loop using Client.wait_for, instead of the on_reaction_add event. The reaction_check function is to make finding the right reactions easier.
from collections.abc import Sequence
from discord import Client
grin = "\N{GRINNING FACE}"
def make_sequence(seq):
if seq is None:
return ()
if isinstance(seq, Sequence) and not isinstance(seq, str):
return seq
else:
return (seq,)
def reaction_check(message=None, emoji=None, author=None, ignore_bot=True):
message = make_sequence(message)
message = tuple(m.id for m in message)
emoji = make_sequence(emoji)
author = make_sequence(author)
def check(reaction, user):
if ignore_bot and user.bot:
return False
if message and reaction.message.id not in message:
return False
if emoji and reaction.emoji not in emoji:
return False
if author and user not in author:
return False
return True
return check
client = Client()
async def background_loop():
await client.wait_until_ready()
channel = client.get_channel(int(*SOME CHANNEL ID*))
msg = await channel.send("React to see help")
await msg.add_reaction(grin)
while not client.is_closed:
res = await client.wait_for('reaction_add', check=reaction_check(message=msg, emoji=grin))
if res: # not None
await msg.edit(content="Moderator commands")
client.loop.create_task(background_loop())
client.run("TOKEN")
来源:https://stackoverflow.com/questions/55798114/if-the-user-reacts-with-i-want-the-bot-to-edit-the-message