【发布时间】:2021-08-25 14:19:05
【问题描述】:
所以我在 discord.py 中制作了一个机器人,但我偶然发现了一个问题。
这是我的代码:
async def make_event(ctx):
with open('stats.json', "r") as f:
users = json.load(f)
event_embed = discord.Embed(title="AN EVENT IS HAPPENING!", description="React to the message to gain some coins!", color=discord.Colour.red())
event_message = await ctx.send(embed=event_embed)
await event_message.add_reaction("????")
await asyncio.sleep(4)
reactors = []
for reaction in event_message.reactions:
reactorsForThatReaction = await reaction.users().flatten()
for user in reactorsForThatReaction:
if str(user.id) not in reactors:
reactors.append(str(user.id))
resultEmbed = discord.Embed(title="Event results", description="The following users won coins:")
for user in reactors:
gain = random.randint(5000, 100000)
users[user]["cash"] += gain
formattedGain = "{:,}".format(gain)
resultEmbed.add_field(name=client.fetch_user(int(user)).name, value=f"{formattedGain} cash.")
await ctx.send(embed=resultEmbed)
基本上,这段代码的作用是制作和发送嵌入(用户对其做出反应),然后机器人处理这些反应并分发硬币。我遇到的问题是机器人根本没有注册event_message.reactions。当我尝试打印出event_message.reactions 时,它返回一个空列表。我不知道这里发生了什么。
有人可以帮忙吗?
【问题讨论】:
标签: python discord.py