Discord bot 扩展运行良好但不起作用

时间:2021-05-02 04:51:16

标签: python discord discord.py bots

我能够很好地加载扩展程序,但是每当我在 Discord 上尝试使用 Qball/.Qball/_Qball 时,机器人都不会回答。

Quokkabot.py(主)

import discord
import random
import os
from discord.ext import commands

client = commands.Bot(command_prefix = '.')

@client.command()
async def load(ctx, extension):
    client.load_extension('.cogs.Quokkabot2')

@client.event
async def on_ready():
    print('{0.user} JOINED THE PARTY!'.format(client))


client.run('token')

Quokkabot2.py (cog)

import discord
from discord.ext import commands

class Commands(commands.Cog):
    def __init__(self, client):
        self.client = client

@commands.command(aliases=['Qball, test'])
async def _Qball(ctx):
    responses = [#answers]
    await ctx.send(f'{random.choice(responses)}')

def setup(client):
    client.add_command(Qball(client))

1 个答案:

答案 0 :(得分:0)

cog 上的命令应定义为该 cog 上的实例方法。

class Commands(commands.Cog):
    def __init__(self, client):
        self.client = client

    @commands.command(aliases=['Qball, test'])
    async def _Qball(self, ctx):
        responses = [#answers]
        await ctx.send(f'{random.choice(responses)}')

然后,在你的主

client = commands.Bot(command_prefix = '.')
client.add_cog(Commands(client))