0
@client.command()
@commands.has_role("Bot Owner")
async def gstart(ctx, mins : int, *, prize: str):
    embed = discord.Embed(title="Giveaway!", description=f"{prize}", color=ctx.author.color)

    end = datetime.datetime.utcnow() + datetime.timedelta(seconds=mins*60)

    embed.add_field(name='Ends At:', value=f"{end} UTC")
    embed.set_footer(text=f'Ends {mins} mintues from now!')

    my_msg = await ctx.send(embed=embed)

    await my_msg.add_reaction("")

    await  asyncio.sleep(mins*60)

    new_msg = await ctx.channel.fetch_message(my_msg.id)

    users = new_msg.reactions[0].users().flatten()
    users.pop(users.index(client.user))

    winner = random.choice(users)

    await ctx.send(f"test! {winner.mention} test {prize}!")

The problem is that when it expires, I get the following error message :

RuntimeWarning: Enable tracemalloc to get the object allocation traceback

What could be the problem?

Axe319
  • 4,255
  • 3
  • 15
  • 31
CICUS
  • 15
  • 3
  • 1
    This is often caused by a missuse of the `asyncio.sleep()` function. Try to delete the extra space between `await` and `asyncio.sleep(mins*60)` as that might be causing issues. – Shunya Jan 21 '21 at 17:35
  • 1
    See: https://stackoverflow.com/questions/54088263/runtimewarning-enable-tracemalloc-to-get-the-object-allocation-traceback-with-a – effprime Jan 21 '21 at 17:38
  • "This is often caused by a missuse of the asyncio.sleep() function. Try to delete the extra space between await and asyncio.sleep(mins*60) as that might be causing issues. – Shunya 45 mins ago" i try dont work :( – CICUS Jan 21 '21 at 18:21

1 Answers1

2

Reaction.users is a coroutine, you should await it

users = await new_msg.reactions[0].users().flatten()

Reference:

Łukasz Kwieciński
  • 14,992
  • 4
  • 21
  • 39