python - Discord 机器人扩展运行良好,但不起作用
问题描述
我能够很好地加载扩展程序,但是每当我在 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))
解决方案
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))
推荐阅读
- google-api - API 密钥对谷歌云翻译无效
- sql - Azure SQL 数据库中的 SQL 作业中的语法错误
- python - django中的url可以传入一个空字符串吗?
- javascript - vue-cli-service serve 和 buid 生成不同的样式
- python - 通过 API 向 JIRA 问题添加请求类型
- jenkins - 使用自定义 settings.xml 时,避免在 Jenkins 声明式管道中使用 Maven / configFileProvider 冗余
- javascript - Angular:如何从后台更新打开的对话框数据?
- cmake - cmake 命令的括号中的术语是什么意思?
- java - querySkuDetailsAsync 正在返回带有 BillingResult 代码 SERVICE_UNAVAILABLE 的空列表
- javascript - 反应本机firebase离线写入+更新在线时不同步