每次尝试连接 Cogs 时都会出现错误 Discord.ext.commands.errors.CommandNotFound:找不到命令“ping”
主要
import discord
import os
from discord.ext import commands
intents = discord.Intents.all()
intents.members=True
token = "token"
bot = commands.Bot(command_prefix='!', intents=intents, help_command=None)
async def load():
for filename in os.listdir('./cogs'):
if filename.endswith('.py'):
await bot.load_extension(f'cogs.{filename[:-3]}')
async def main():
await load()
await bot.start("MTIyOTMxMDU3NzY2MzU0MTMwOQ.Ga2B0l.iBU8_AT1D3HOBL32JYKgDxQ1YutvUdJZjOC0J0")
bot.run("token")
齿轮
import discord
from discord.ext import commands
class ping(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_ready(self):
print("bot Is Online")
@commands.command()
async def ping(self, ctx):
await ctx.send("pong")
async def setup(bot):
await bot.add_cog(ping(bot))
我尝试加载和卸载,但这些命令也没有帮助
重置您的令牌。
您实际上并没有加载任何齿轮,因为您是通过
Bot.run
启动机器人,您需要调用 main()
函数来启动带有扩展加载的机器人。
将您的
bot.run()
替换为 asyncio.run(main())
。