[英]Discord.py respond to reactions
How would I be able to wait for a reaction and then use that reaction as a response我如何能够等待反应然后使用该反应作为回应
What I want the code to do:我想要代码做什么:
User ->.buy用户 ->.buy
Bot -> "How would you like to purchase" Bot -> “你想如何购买”
User -> Reacts with 1️⃣用户 -> 与 1️⃣ 反应
Bot -> Says response for reaction 1️⃣ Bot -> 说响应 1️⃣
Here is my code so far:到目前为止,这是我的代码:
message = await ctx.send("How would you like to purchase")
for emoji in ('0️⃣', '1️⃣', '2️⃣', '3️⃣', '4️⃣', '5️⃣'):
await message.add_reaction(emoji)
I want the bot to be able to respond to each of these reactions with different responses我希望机器人能够对这些反应中的每一个做出不同的反应
If you're trying to wait for a response from a reaction you can try using the on_reaction_add
event.如果您尝试等待响应的响应,您可以尝试使用on_reaction_add
事件。 Something like this may work:像这样的东西可能会起作用:
@client.event
async def on_reaction_add(reaction, user):
if reaction.message.author.bot: #checks if message is from bot
if reaction.emoji == '0️⃣':
#process for this reaction
elif reaction.emoji == '1️⃣':
#process for this reaction
#this goes on for as many reactions you have
Alternatively you can use a switch instead of a block of if elif statements.或者,您可以使用开关而不是 if elif 语句块。 You can use a switch statement like this: switch = {'0️⃣':#process,'1️⃣':#process, #and so on}
你可以使用这样的 switch 语句: switch = {'0️⃣':#process,'1️⃣':#process, #and so on}
With this you can do:有了这个,你可以这样做:
switch.get(reaction.emoji)
This will get the process from the specific reaction in the switch statement.这将从switch语句中的具体反应中得到流程。 I hope this may be of help.我希望这可能会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.