python - Discord.py - 即使我定义了命令 ping,也没有定义它
问题描述
我正在关注 discord.py 的教程,而教书的人变得非常复杂。他告诉使用创建一个 main_cogs.py 文件,我做到了。
这是他的确切代码:
import config
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix='-')
class Test(commands.Cog):
def __init__(self,bot):
self.bot= bot
@commands.command
async def ping(self ,ctx):
await ctx.send("Pong")
bot.run(config.token)
BTW config 是一个包含令牌和所有内容的文件。
当我运行它并输入 -ping(in chat) 时,我在控制台中得到了这个,而在聊天中什么也没有:
Ignoring exception in command None:
discord.ext.commands.errors.CommandNotFound: Command "ping" is not found
对他来说,它只是工作。
感谢您的帮助!
解决方案
更改
@bot.command()
为@commands.command()
从中删除def __init__(self,bot,ctx):
ctxdef __init__(self, bot):
推荐阅读
- fortran - 如何使用 MPI-IO 在单个格式化(可读)文件中使用 MPI 进行绘图
- java - com.sun.net.ssl.internal.ssl 包不可见
- css - 使用 css 单位 em 缩放 SVG 图标的不同行为
- owl - 定义一个实例属于某个类
- javascript - 如何阻止我的位置:固定 div 在光滑的滑块中移动?
- java - 为什么 intellij 代码自动完成功能不起作用?
- python - 为什么我的 LPvariable 类型在纸浆中不受尊重?
- sql-server - Azure 逻辑应用上的存储过程失败
- html - 更改html中标题的颜色
- video - 如何使用 ffmpeg 将 WebM 音频(Opus)和 MP4 视频(H.264)合并为一个 MP4 文件