反应列表混乱



0

我正试图通过使用discord机器人为英雄联盟球队(每方5支(编写一个简单的团队随机化器。到目前为止,我能够发送消息并获得反应,但我不知道如何返回对机器人消息做出反应的用户的列表,以随机化团队。

因此,只有当10名玩家对消息做出反应时,机器人才会返回列表。当前代码:

async def scrim2(ctx, bot):
embed = discord.Embed(
title='*SORTEIO X5 DOS CRIAS*',
description='Deseja sortear as lanes? n ✅: Sim n ❌: Não',
colour= discord.Colour.blue()
)
await ctx.channel.purge(limit=1)
msg_scrim = await ctx.send(embed=embed)
await msg_scrim.add_reaction('✅')
await msg_scrim.add_reaction('❌')
def checkReaction(reaction, user):
user != bot.user and (str(reaction.emoji) == '✅' or str(reaction.emoji) == '❌')
def checkReaction1(reaction, user, limit):
return user != bot.user and (limit == 10) and (str(reaction.emoji) == '🎲')
reaction, user = await bot.wait_for('reaction_add', timeout=200, check=checkReaction)
if str(reaction.emoji) == '✅':
msg_players1 = await ctx.send('Invocadores, reajam abaixo: ')
await msg_players1.add_reaction('🎲')
reaction, user = await bot.wait_for('reaction_add', timeout=200, check=checkReaction1)
await scrim_sorteio(ctx, bot)
pass
elif str(reaction.emoji) == '❌':
msg_players2 = await ctx.send('Invocadores, reajam abaixo: ')
await msg_players2.add_reaction('🎲')
reaction, user = await bot.wait_for('reaction_add', timeout=200, check=checkReaction1)
await scrim_sorteio(ctx, bot)
pass

基本上,我会创建另一个函数scrim_sorteio来获取对消息做出反应的球员名单,然后随机分组。

我对编码很陌生,所以我很感激你的帮助。此外,当我运行代码时,没有给出任何错误或任何东西。

更新:

reaction, user = await bot.wait_for('reaction_add', timeout=200, check=checkReaction)
if str(reaction.emoji) == '✅':
msg_players1 = await ctx.send('Invocadores, reajam abaixo: ')
await msg_players1.add_reaction('🎲')
reaction, user = await bot.wait_for('reaction_add', timeout=200, check=checkReaction1)
players1 = msg_players1.reactions
print(players1)
await ctx.send(f'Time 1 {players1}')

现在这只是每次打印一个空列表。

如果您想获得反应列表,可以使用message.reactions

我认为,它可以这样工作:

if len(msg_scrim.reactions) == 10:
players = msg_scrim.reactions
random.shuffle(players)
team1 = players[0:5]
team2 = players[5:10]

文件:https://discordpy.readthedocs.io/en/stable/api.html#discord.Message.reactions

最新更新