@@ -87,6 +87,13 @@ def _name_filter(c: Any) -> str:
87
87
)
88
88
89
89
90
+ def _validate_name_prefix (base_class : type , name : str ) -> None :
91
+ if name .startswith (("cog_" , "bot_" )):
92
+ raise TypeError (
93
+ f"Commands or listeners must not start with cog_ or bot_ (in method { base_class } .{ name } )"
94
+ )
95
+
96
+
90
97
class CogMeta (type ):
91
98
"""A metaclass for defining a cog.
92
99
@@ -204,7 +211,8 @@ def __new__(cls: type[CogMeta], *args: Any, **kwargs: Any) -> CogMeta:
204
211
if getattr (value , "parent" , None ) and isinstance (
205
212
value , ApplicationCommand
206
213
):
207
- # Skip commands if they are a part of a group
214
+ # Skip application commands if they are a part of a group
215
+ # Since they are already added when the group is added
208
216
continue
209
217
210
218
is_static_method = isinstance (value , staticmethod )
@@ -216,8 +224,7 @@ def __new__(cls: type[CogMeta], *args: Any, **kwargs: Any) -> CogMeta:
216
224
f"Command in method { base } .{ elem !r} must not be"
217
225
" staticmethod."
218
226
)
219
- if elem .startswith (("cog_" , "bot_" )):
220
- raise TypeError (no_bot_cog .format (base , elem ))
227
+ _validate_name_prefix (base , elem )
221
228
commands [elem ] = value
222
229
223
230
if _is_bridge_command (value ) and not value .parent :
@@ -226,8 +233,7 @@ def __new__(cls: type[CogMeta], *args: Any, **kwargs: Any) -> CogMeta:
226
233
f"Command in method { base } .{ elem !r} must not be"
227
234
" staticmethod."
228
235
)
229
- if elem .startswith (("cog_" , "bot_" )):
230
- raise TypeError (no_bot_cog .format (base , elem ))
236
+ _validate_name_prefix (base , elem )
231
237
232
238
commands [f"ext_{ elem } " ] = value .ext_variant
233
239
commands [f"app_{ elem } " ] = value .slash_variant
@@ -243,8 +249,7 @@ def __new__(cls: type[CogMeta], *args: Any, **kwargs: Any) -> CogMeta:
243
249
except AttributeError :
244
250
continue
245
251
else :
246
- if elem .startswith (("cog_" , "bot_" )):
247
- raise TypeError (no_bot_cog .format (base , elem ))
252
+ _validate_name_prefix (base , elem )
248
253
listeners [elem ] = value
249
254
250
255
new_cls .__cog_commands__ = list (commands .values ())
0 commit comments