繁体   English   中英

我如何将 discord 反应保存为变量

[英]How do i save discord reaction as a variable

我有这个代码发送一条带有 4 个反应的消息,有没有办法接受用户输入的第一个反应(如果用户选择另一个选项,它只需要一个输入,它会覆盖第一个也可以的)和将其保存为变量以供以后使用?

import discord
import os
client = discord.Client()
some_list = []
msg = None

    
@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))
@client.event
async def on_message(message):
  if message.author == client.user:
    return
  msg = await message.channel.send("**Question 1?**")
  reactions = ['1️⃣','2️⃣','3️⃣','4️⃣']
  for emoji in reactions: 
    await msg.add_reaction(emoji)
@client.event
async def on_reaction_add(reaction, user):
    if reaction.message == msg:
        some_list.append(user)
client.run("token")

提前致谢!

你真的应该使用wait_for一个如何使用它的例子可以在我之前的回答中找到: Getting input from reactor not working discord.py

如果你不想 go 和 wait_for,你真的应该使用字典。

import discord
import os
client = discord.Client()
some_dict = {}
msg = None

    
@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))
@client.event
async def on_message(message):
  if message.author == client.user:
    return
  msg = await message.channel.send("**Question 1?**")
  reactions = ['1️⃣','2️⃣','3️⃣','4️⃣']
  for emoji in reactions: 
    await msg.add_reaction(emoji)
@client.event
async def on_reaction_add(reaction, user):
    if reaction.message == msg:
        some_dict[user.id] = str(reaction.emoji)
client.run("token")

然后您可以使用some_dict[user.id]访问它

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM