我能够很好地加载扩展程序,但是每当我在 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))
答案 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))