@@ -1010,9 +1010,17 @@ async def get_contexts(self, message, *, cls=commands.Context):
1010
1010
1011
1011
invoker = view .get_word ().lower ()
1012
1012
1013
+ # Check if a snippet is being called.
1014
+ # This needs to be done before checking for aliases since
1015
+ # snippets can have multiple words.
1016
+ try :
1017
+ snippet_text = self .snippets [message .content .removeprefix (invoked_prefix )]
1018
+ except KeyError :
1019
+ snippet_text = None
1020
+
1013
1021
# Check if there is any aliases being called.
1014
1022
alias = self .aliases .get (invoker )
1015
- if alias is not None :
1023
+ if alias is not None and snippet_text is None :
1016
1024
ctxs = []
1017
1025
aliases = normalize_alias (alias , message .content [len (f"{ invoked_prefix } { invoker } " ) :])
1018
1026
if not aliases :
@@ -1028,7 +1036,6 @@ async def get_contexts(self, message, *, cls=commands.Context):
1028
1036
else :
1029
1037
command = self ._get_snippet_command ()
1030
1038
command_invocation_text = f'{ invoked_prefix } { command } { snippet_text } '
1031
-
1032
1039
view = StringView (invoked_prefix + command_invocation_text )
1033
1040
ctx_ = cls (prefix = self .prefix , view = view , bot = self , message = message )
1034
1041
ctx_ .thread = thread
@@ -1040,19 +1047,16 @@ async def get_contexts(self, message, *, cls=commands.Context):
1040
1047
1041
1048
ctx .thread = thread
1042
1049
1043
- try :
1044
- snippet_text = self .snippets [invoker ]
1045
- except KeyError :
1046
- # Process regular commands
1047
- ctx .command = self .all_commands .get (invoker )
1048
- ctx .invoked_with = invoker
1049
- else :
1050
+ if snippet_text is not None :
1050
1051
# Process snippets
1051
1052
ctx .command = self ._get_snippet_command ()
1052
1053
reply_view = StringView (f'{ invoked_prefix } { ctx .command } { snippet_text } ' )
1053
1054
discord .utils .find (reply_view .skip_string , prefixes )
1054
1055
ctx .invoked_with = reply_view .get_word ().lower ()
1055
1056
ctx .view = reply_view
1057
+ else :
1058
+ ctx .command = self .all_commands .get (invoker )
1059
+ ctx .invoked_with = invoker
1056
1060
1057
1061
return [ctx ]
1058
1062
0 commit comments