Reputation: 3
I am making a bot for discord. I'm attempting to make two cogs: a ping-pong cog and a magic 8 ball cog. Ping-pong works great, but when I give command for the 8ball, I get the following error:
Ignoring exception in command None: discord.ext.commands.errors.CommandNotFound: Command "eightball" is not found
Here are the sections of code that pertain to the issue:
Base bot:
@rat.command()
async def load(ctx, extension):
rat.load_extension(f'Cogs.{extension}')
@rat.command()
async def unload(ctx, extension):
rat.unload_extension(f'Cogs.{extension}')
for filename in os.listdir('./Cogs'):
if filename.endswith('.py'):
rat.load_extension(f'Cogs.{filename[:-3]}')
Ping-Pong cog:
import os
import discord
from discord.ext import commands
class Pong(commands.Cog):
def __init__(self, rat):
self.rat = rat
@commands.command()
async def ping(self, ctx):
await ctx.send('Pong!')
def setup(rat):
rat.add_cog(Pong(rat))
Failed 8Ball cog:
import os
import random
import discord
from discord.ext import commands
class Fortune(commands.Cog):
def __init__(self, rat):
self.rat = rat
@commands.command(aliases=['8B', '8ball', '8Ball'])
async def eightball(self, ctx, *, question):
responses = ['It is decidedly so.',
'Without a doubt.',
'Yes, definitely.',
'As I see it, yes.',
'Most likely.',
'Signs point to yes.',
'Reply hazy, try again.',
'Ask again, later.',
'Better not tell you now.',
'Cannot predict now.',
'Concentrate and ask again.',
'Do not count on it.',
'My reply is no.',
'My sources say no.',
'Outlook not so good.',
'I doubt it.']
await ctx.send(f'Question: {question}\nAnswer: {random.choice(responses)}')
def setup(rat):
rat.add_cog(Fortune(rat))
Upvotes: 0
Views: 1229
Reputation: 198
Your eightball function should be indented to be inside of the Fortune class:
import os
import random
import discord
from discord.ext import commands
class Fortune(commands.Cog):
def __init__(self, rat):
self.rat = rat
@commands.command(aliases=['8B', '8ball', '8Ball'])
async def eightball(self, ctx, *, question):
responses = ['It is decidedly so.',
'Without a doubt.',
'Yes, definitely.',
'As I see it, yes.',
'Most likely.',
'Signs point to yes.',
'Reply hazy, try again.',
'Ask again, later.',
'Better not tell you now.',
'Cannot predict now.',
'Concentrate and ask again.',
'Do not count on it.',
'My reply is no.',
'My sources say no.',
'Outlook not so good.',
'I doubt it.']
await ctx.send(f'Question: {question}\nAnswer: {random.choice(responses)}')
def setup(rat):
rat.add_cog(Fortune(rat))
Upvotes: 1