python - Discord.py 查找谁对消息做出了反应
问题描述
我正在编写一个不和谐的机器人并创建一个游戏。我需要让使用特定表情符号对消息做出反应的用户添加到列表中。我怎样才能做到这一点?
(下面是我的代码)
@client.command(aliases=['rr'])
async def roletarussa(ctx):
embed = discord.Embed(title="ROLETA RUSSA", description="Reaja com ✅ para participar!")
embed.set_thumbnail(
url="https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcRa7rdwxpSOiReyDvnVd6MzqDg33rtQrxhoUw&usqp=CAU")
embed.add_field(name="Só os brabo consegue entrar nesse web desafio ",
value="Vai logo entra nesse bagaça medroso!", inline=False)
embed.set_image(url='https://media1.tenor.com/images/64e0334d77b0976b808147bd160b8534/tenor.gif?itemid=12379724')
message = await ctx.send(embed=embed)
await message.add_reaction("✅")
def check(reaction, user):
return user == ctx.author and str(reaction.emoji) in ['✅']
while True:
try:
reaction, user = await client.wait_for("reaction_add", timeout=60, check=check)
if str(reaction.emoji) == "✅":
await ctx.send('{} vai participar'.format(user))
await message.remove_reaction(reaction, user)
else:
await message.remove_reaction(reaction, user)
except asyncio.TimeoutError:
await message.delete()
break
# ending the loop if user doesn't react after x seconds
@client.command()
async def startrr(ctx):
players = []
maxlenght = 6
while len(players) < maxlenght:
rrp = ctx.message.author.mention
players.append(rrp)
players = list(set(players))
else:
await ctx.send('Sem mais vagas para o jogo.')
await ctx.send(players)
我需要知道谁对消息做出反应并存储在“玩家”列表中。
解决方案
推荐阅读
- javascript - 从 7 升级到 Babel-loader 8?我需要改变什么?
- node.js - 如何在 NodeJS(运行 npm 脚本)中找到 spawn 的错误原因?
- vba - VBA:如果列的单元格(已知列号)等于一个值,如何使用 if 条件检查?
- linux-kernel - 旧内核模块在重启后仍然存在
- cron - Crontab 运行使用虚拟环境的 python 脚本
- c# - 我的 .aspx 页面之一显示错误消息:引发了“System.OutOfMemoryException”类型的异常
- xamarin - How can I make my Xamarin.Forms for iOS and Android application show a splash screen as soon as possible after a user has opened the application?
- omnet++ - 在Omnet++中,哪里可以找到不同的参数值?
- json - 如何将数据从 Node.JS 传输到 ExpressJS html?
- mysql - 循环遍历 JSON 文件并使用 node.js 插入 mysql 数据库表