@@ -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
@@ -176,10 +183,6 @@ def __new__(cls: type[CogMeta], *args: Any, **kwargs: Any) -> CogMeta:
176
183
177
184
commands = {}
178
185
listeners = {}
179
- no_bot_cog = (
180
- "Commands or listeners must not start with cog_ or bot_ (in method"
181
- " {0.__name__}.{1})"
182
- )
183
186
184
187
new_cls = super ().__new__ (cls , name , bases , attrs , ** kwargs )
185
188
@@ -204,7 +207,8 @@ def __new__(cls: type[CogMeta], *args: Any, **kwargs: Any) -> CogMeta:
204
207
if getattr (value , "parent" , None ) and isinstance (
205
208
value , ApplicationCommand
206
209
):
207
- # Skip commands if they are a part of a group
210
+ # Skip application commands if they are a part of a group
211
+ # Since they are already added when the group is added
208
212
continue
209
213
210
214
is_static_method = isinstance (value , staticmethod )
@@ -216,8 +220,7 @@ def __new__(cls: type[CogMeta], *args: Any, **kwargs: Any) -> CogMeta:
216
220
f"Command in method { base } .{ elem !r} must not be"
217
221
" staticmethod."
218
222
)
219
- if elem .startswith (("cog_" , "bot_" )):
220
- raise TypeError (no_bot_cog .format (base , elem ))
223
+ _validate_name_prefix (base , elem )
221
224
commands [elem ] = value
222
225
223
226
if _is_bridge_command (value ) and not value .parent :
@@ -226,8 +229,7 @@ def __new__(cls: type[CogMeta], *args: Any, **kwargs: Any) -> CogMeta:
226
229
f"Command in method { base } .{ elem !r} must not be"
227
230
" staticmethod."
228
231
)
229
- if elem .startswith (("cog_" , "bot_" )):
230
- raise TypeError (no_bot_cog .format (base , elem ))
232
+ _validate_name_prefix (base , elem )
231
233
232
234
commands [f"ext_{ elem } " ] = value .ext_variant
233
235
commands [f"app_{ elem } " ] = value .slash_variant
@@ -243,8 +245,7 @@ def __new__(cls: type[CogMeta], *args: Any, **kwargs: Any) -> CogMeta:
243
245
except AttributeError :
244
246
continue
245
247
else :
246
- if elem .startswith (("cog_" , "bot_" )):
247
- raise TypeError (no_bot_cog .format (base , elem ))
248
+ _validate_name_prefix (base , elem )
248
249
listeners [elem ] = value
249
250
250
251
new_cls .__cog_commands__ = list (commands .values ())
0 commit comments