If The User Reacts With 😃, I Want The Bot To Edit The Message
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.ed
Solution 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 importSequencefrom discord import Client
grin = "\N{GRINNING FACE}"defmake_sequence(seq):
if seq isNone:
return ()
ifisinstance(seq, Sequence) andnotisinstance(seq, str):
return seq
else:
return (seq,)
defreaction_check(message=None, emoji=None, author=None, ignore_bot=True):
message = make_sequence(message)
message = tuple(m.idfor m in message)
emoji = make_sequence(emoji)
author = make_sequence(author)
defcheck(reaction, user):
if ignore_bot and user.bot:
returnFalseif message and reaction.message.idnotin message:
returnFalseif emoji and reaction.emoji notin emoji:
returnFalseif author and user notin author:
returnFalsereturnTruereturn check
client = Client()
asyncdefbackground_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)
whilenot client.is_closed:
res = await client.wait_for('reaction_add', check=reaction_check(message=msg, emoji=grin))
if res: # not Noneawait msg.edit(content="Moderator commands")
client.loop.create_task(background_loop())
client.run("TOKEN")
Solution 2:
Or you can use the package discord_interactive_help
, which allow you to display a bunch of pages and let your user interact with this manual through reactions.
Disclaimer : I am the author of discord_interactive_help
.
Solution 3:
You should be able to detect the reaction with your current code, your problem would be your edit.
channel = a.channel
msg_id = a.idif reaction.emoji == "😃":
msg = await channel.fetch_message(msg_id)
await msg.edit(content = content)
Post a Comment for "If The User Reacts With 😃, I Want The Bot To Edit The Message"