-
Notifications
You must be signed in to change notification settings - Fork 60
Closed
Description
It doesn't seem like the subclassing guide works -- by default, Python doesn't inherit decorators from parents (see eg https://stackoverflow.com/questions/3421337/accessing-a-decorator-in-a-parent-class-from-the-child-in-python for discussion of how to make it work), and py-cord doesn't seem to have done the custom work to make it work. The result is that, eg, the @slash_command
decorator is undefined in a subclass.
To Reproduce
Copy the first example from https://guide.pycord.dev/popular-topics/subclassing-bots:
$ cat > sample.py
import discord
class MyBot(discord.Bot): # subclass discord.Bot
async def on_ready(self): # override the on_ready event
print('Logged in as')
print(self.user.name)
print(self.user.id)
print('------')
@slash_command() # create a slash command
async def ping(self, ctx):
await ctx.respond('Pong!')
bot = MyBot()
bot.run('token')
$ python3 sample.py
Traceback (most recent call last):
File "sample.py", line 3, in <module>
class MyBot(discord.Bot): # subclass discord.Bot
File "sample.py", line 10, in MyBot
@slash_command() # create a slash command
NameError: name 'slash_command' is not defined
Expected behavior
Bot runs, with a ping
slash command defined.
Metadata
Metadata
Assignees
Labels
No labels