File tree Expand file tree Collapse file tree 2 files changed +18
-8
lines changed Expand file tree Collapse file tree 2 files changed +18
-8
lines changed Original file line number Diff line number Diff line change @@ -569,18 +569,16 @@ async def on_application_command_error(
569
569
570
570
This only fires if you do not specify any listeners for command error.
571
571
"""
572
- # TODO
573
- # if self.extra_events.get('on_application_command_error', None):
574
- # return
572
+ if self .extra_events .get ('on_application_command_error' , None ):
573
+ return
575
574
576
575
command = context .command
577
576
if command and command .has_error_handler ():
578
577
return
579
578
580
- # TODO
581
- # cog = context.cog
582
- # if cog and cog.has_error_handler():
583
- # return
579
+ cog = context .cog
580
+ if cog and cog .has_error_handler ():
581
+ return
584
582
585
583
print (f"Ignoring exception in command { context .command } :" , file = sys .stderr )
586
584
traceback .print_exception (
Original file line number Diff line number Diff line change 22
22
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23
23
DEALINGS IN THE SOFTWARE.
24
24
"""
25
+ from __future__ import annotations
25
26
26
27
from typing import TYPE_CHECKING , Optional , Union
27
28
31
32
import discord
32
33
from discord .state import ConnectionState
33
34
35
+ from .commands import ApplicationCommand
36
+ from ..cog import Cog
37
+
34
38
from ..guild import Guild
35
39
from ..interactions import Interaction , InteractionResponse
36
40
from ..member import Member
@@ -63,7 +67,7 @@ class ApplicationContext(discord.abc.Messageable):
63
67
def __init__ (self , bot : "discord.Bot" , interaction : Interaction ):
64
68
self .bot = bot
65
69
self .interaction = interaction
66
- self .command = None
70
+ self .command : ApplicationCommand = None # type: ignore
67
71
self ._state : ConnectionState = self .interaction ._state
68
72
69
73
async def _get_channel (self ) -> discord .abc .Messageable :
@@ -130,3 +134,11 @@ async def delete(self):
130
134
@property
131
135
def edit (self ):
132
136
return self .interaction .edit_original_message
137
+
138
+ @property
139
+ def cog (self ) -> Optional [Cog ]:
140
+ """Optional[:class:`.Cog`]: Returns the cog associated with this context's command. None if it does not exist."""
141
+ if self .command is None :
142
+ return None
143
+
144
+ return self .command .cog
You can’t perform that action at this time.
0 commit comments