我正在尝试为我的 Discord.py 机器人制作一个赠品命令。我使用了 YouTube 的指南:https://youtu.be/s531M7jLh6A 但在 winner = random.choice(users) part:
完整命令:
@bot.command()
@commands.has_permissions(manage_guild=True)
async def gstart(ctx, mins : int, *, prize:str):
embed=discord.Embed(color=0x0f84eb)
embed.add_field(name="Giveaway!", value=f"{prize}", inline=False)
end = datetime.datetime.utcnow() + datetime.timedelta(seconds = mins*60)
embed.add_field(name="Kończy się:", value= f"{end} UTC")
embed.set_footer(text="<> and hosted with ♡ by Maciejka")
my_msg = await ctx.send(embed=embed)
await my_msg.add_reaction('✋')
await asyncio.sleep(10)
new_msg = await ctx.channel.fetch_message(my_msg.id)
users = new_msg.reactions[0].users().flatten()
users.pop(users.index(bot.user))
print('1')
winner = random.choice(users)
print('3')
await ctx.send(f"Congrats! {winner} won {prize}!")
我得到的完整错误:
/usr/lib/python3.7/asyncio/events.py:88: RuntimeWarning: coroutine '_AsyncIterator.flatten' was never awaited
self._context.run(self._callback, *self._args)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
答案 0 :(得分:0)
您忘记等待一行。如错误所示。如果您无法从错误中弄清楚这一点,您可能需要查看一些教程。谢谢。 :)