#Having a Async in a dynamic cooldown

1 messages · Page 1 of 1 (latest)

chilly wyvern
#

Hello!

Ignoring exception in on_interaction
Traceback (most recent call last):
  File "/home/container/.local/lib/python3.8/site-packages/discord/client.py", line 382, in _run_event
    await coro(*args, **kwargs)
  File "/home/container/.local/lib/python3.8/site-packages/discord/bot.py", line 1044, in on_interaction
    await self.process_application_commands(interaction)
  File "/home/container/.local/lib/python3.8/site-packages/discord/bot.py", line 736, in process_application_commands
    await self.invoke_application_command(ctx)
  File "/home/container/.local/lib/python3.8/site-packages/discord/bot.py", line 992, in invoke_application_command
    await ctx.command.invoke(ctx)
  File "/home/container/.local/lib/python3.8/site-packages/discord/commands/core.py", line 355, in invoke
    await self.prepare(ctx)
  File "/home/container/.local/lib/python3.8/site-packages/discord/commands/core.py", line 286, in prepare
    self._prepare_cooldowns(ctx)
  File "/home/container/.local/lib/python3.8/site-packages/discord/commands/core.py", line 266, in _prepare_cooldowns
    retry_after = bucket.update_rate_limit(current)
AttributeError: 'coroutine' object has no attribute 'update_rate_limit'
#
async def misc_cooldown(message):
    y = await timed_stuff_collection.find_one({"_id":message.author.id})
    commonpremactive_amt = y["premium"]   
    if commonpremactive_amt == True:
        return commands.Cooldown(1, 5)
    else:
        return commands.Cooldown(1, 10)
    
async def moneyearn_cooldown(message):
    y = await timed_stuff_collection.find_one({"_id":message.author.id})
    commonpremactive_amt = y["premium"]   
    if commonpremactive_amt == True:
        return commands.Cooldown(1, 15)
    else:
        return commands.Cooldown(1, 30)```
#

i understand the problem that dynamic cooldown only works on def and not async def
but any way to to run it in async or since the await in y = await timed_stuff_collection.find_one({"_id":message.author.id}) is because of pymongo "motor" so its asynchronous

#

@"The Dark" suggested that i do Either use a sync client for the cooldown
Or cache whatever info you need

#

any way/example to impelemt this or any fix? thx Heart