我可以很好地加载扩展,但每当我在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))
齿轮上的命令应定义为该齿轮上的实例方法。
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))