尝试在 discord.py 中 运行 多个齿轮。只有一个功能

Trying to run multiple cogs in discord.py. Only one functions

我正在制作一个不和谐的机器人。我正在尝试制作两个齿轮:一个乒乓球齿轮和一个神奇的 8 球齿轮。 乒乓球效果很好,但是当我发出 8 号球的命令时,出现以下错误:

忽略命令中的异常 None: discord.ext.commands.errors.CommandNotFound: 未找到命令“eightball”

以下是与该问题相关的代码部分:

基地机器人:

@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]}')

乒乓齿轮:

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

失败的 8Ball 齿轮:

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

你的 eightball 函数应该缩进到 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))