Reputation: 57
I'm trying to create a bot with the help of Python and the discord.py library.
I have two files main.py, and MyBot.py.
Main.py
from MyBot import MyBot
bot = MyBot()
bot.run("API_KEY")
MyBot.py
from discord.ext import commands
from discord.ext.commands import command
class MyBot(commands.Bot):
def __init__(self):
super().__init__(command_prefix="!")
async def on_ready(self):
print("Bot ready.")
@command(name="hello", help="Say hello")
async def hello(ctx, arg):
await ctx.channel.send("Hello you!")
When running the command !hello
I get an exception in my script
Ignoring exception in command None:
discord.ext.commands.errors.CommandNotFound: Command "hello" is not found
I think the error comes from the way I use the decorator, but I have no idea how to fix it. Please note that I'm currently learning python co-routines & decorators. So this is a new notion to me.
Anyway, thanks a lot to anyone willing to help me :)
Upvotes: 2
Views: 770
Reputation: 1417
If you would like to inherit from commands.Bot use:
from discord.ext import commands
from discord.ext.commands import command
class MyBot(commands.Bot):
def __init__(self):
super().__init__(command_prefix="!")
async def on_ready(self):
print("Bot ready.")
bot = MyBot()
@bot.command(name="hello", help="Say hello")
async def hello(ctx, arg):
await ctx.channel.send("Hello you!")
bot.run('token')
If you are inheriting from MyBot as a method to group commands use cogs. In its current state, inheriting from commands.Bot has no practical usage.
Upvotes: 1