【问题标题】:Discord.py giveaway command random choice from reactions errorDiscord.py 赠品命令从反应错误中随机选择
【发布时间】: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


    【解决方案1】:

    有一行你忘了等待。如错误中所见。如果您无法从错误中找出答案,您可能需要查看一些教程。谢谢。 :)

    【讨论】:

    • 是的,我知道我没有等待这个,但是随机的。*某些东西*不需要等待,等待这个之后它仍然有错误。
    猜你喜欢
    • 2021-03-20
    • 2021-06-02
    • 1970-01-01
    • 2021-11-01
    • 2021-07-20
    • 2021-05-25
    • 2021-05-02
    • 1970-01-01
    • 2020-03-17
    相关资源
    最近更新 更多