首页 > 解决方案 > 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

对他来说,它只是工作。

视频

感谢您的帮助!

标签: pythondiscorddiscord.py

解决方案


更改 @bot.command()@commands.command()

从中删除def __init__(self,bot,ctx):ctxdef __init__(self, bot):


推荐阅读