【发布时间】:2020-12-20 04:47:51
【问题描述】:
我正在尝试为我的 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
【问题讨论】:
标签: python discord discord.py