#Subclassing - NameError name 'slash_command' is not defined

1 messages · Page 1 of 1 (latest)

plucky harbor
#

I was trying to follow the subclassing example @ https://guide.pycord.dev/popular-topics/subclassing-bots/ but it throws the exception i wrote in the title

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')

Is there a workaround for this?

Subclassing is a popular way of creating Discord Bots. Explore how you can create a Discord bot by subclassing.

plucky harbor
#

I tried with this, but for some reason it doesnt register the ping command

import discord
from discord.commands import slash_command


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")
#

without subclassing it works perfectly, so it is not a bot perms issue