Voxel-Fox-Ltd/Novus

`Command.reset_cooldown` not functional with application commands

Closed this issue · 1 comments

Summary

discord.ext.Command.reset_cooldown does not work when given a SlashContext, and results in a NoneType AttributeError internally when trying to use any attributes of SlashContext.message

Reproduction Steps

  1. Have a discord.ext.commands.Command object and a discord.ext.commands.SlashContext object
  2. Run <command instance>.reset_cooldown(<slash context instance>)

Minimal Reproducible Code

# An example of where this could be encountered

import discord  # type: ignore
from discord.ext import commands  # type: ignore


class ErrorHandlerCog(commands.Cog):
    @commands.Cog.listener()
    async def on_command_error(
        self,
        ctx: commands.Context,
        _: commands.CommandError,
    ):
        if ctx.command is not None:
           ctx.command.reset_cooldown(ctx)

Expected Results

I expect discord.ext.Command.reset_cooldown to function well when supplied a context without a message.

Actual Results

Internal AttributeError ('NoneType' object has no attribute 'author') at line 62 of discord/ext/commands/cooldowns.py

Ignoring exception in on_command_error
Traceback (most recent call last):                                                               _command_error
  File "C:\Users\rdtla\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.p                           n reset_cooldowny", line 330, in _run_event                                                                      ands\core.py", line 1037, i
    await coro(*args, **kwargs)                                                                                             5, in get_bucket
  File "C:\Users\rdtla\OneDrive\Documents\GitHub\original-pp-bot\cogs\errors.py", line 119, in on_command_error                                                                                   ands\cooldowns.py", line 246, in _bucket_key
    return ctx.command.reset_cooldown(ctx)
  File "C:\Users\rdtla\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\comm                           , in __call__ands\core.py", line 1037, in reset_cooldown                                                      ands\cooldowns.py", line 22
    bucket = self._buckets.get_bucket(ctx.message)                                                                          , in get_key
  File "C:\Users\rdtla\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\cooldowns.py", line 245, in get_bucket                                                      ands\cooldowns.py", line 79
    key = self._bucket_key(message)
  File "C:\Users\rdtla\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\cooldowns.py", line 226, in _bucket_key                                                     ands\cooldowns.py", line 62
    return self._type(msg)
  File "C:\Users\rdtla\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\cooldowns.py", line 79, in __call__
    return self.get_key(msg)
  File "C:\Users\rdtla\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\cooldowns.py", line 62, in get_key
    return msg.author.id
AttributeError: 'NoneType' object has no attribute 'author'

Intents

intents = discord.Intents.default()

System Information

  • Python v3.10.2-final
  • Novus v0.0.5-alpha
    • Novus pkg_resources: v0.0.7a3827+gb119370
  • aiohttp v3.7.4.post0
  • system info: Windows 10 10.0.19044

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

Additional Context

I have only tested this with slash commands specifically.

Closed with cca2ffb.