代码之家  ›  专栏  ›  技术社区  ›  venout163

discord.ext.commands.errors.CommandNotFound:找不到命令“hello”

  •  0
  • venout163  · 技术社区  · 3 年前

    当我启动我的机器人并打字时!你好,我收到这个错误,这是我的代码

    import discord
    from discord.ext import commands
    import os
    import asyncio
    
    intents = discord.Intents.all()
    intents.members = True
    client = commands.Bot(command_prefix='!', intents=intents)
    
    
    @client.command()
    async def load(ctx, extension):
        client.load_extension(f'cogs.{extension}')
    
    @client.command()
    async def unload(ctx, extension):
        client.unload_extension(f'cogs.{extension}')
    
    for filename in os.listdir('./cogs'):
        if filename.endswith('.py'):
            client.load_extension(f'cogs,{filename[:-3]}')
    client.run("*")
    

    用于齿轮的第二个文件example.py

    import discord
    from discord.ext import commands
    
    class example(commands.Cog):
        def __init__(self, client):
            self.client = client
    
        @commands.Cog.listener()
        async def on_ready(self):
            print('Bot is ready')
    
        @commands.command()
        async def hello(self, ctx):
            await ctx.send('Hi')
    
    
    async def setup(client):
        await client.add.cog(example(client))
    

    如果有人能帮我解决这个问题,我将非常高兴

    0 回复  |  直到 3 年前
        1
  •  0
  •   kariga    2 年前

    而不是做 client.add.cog 你应该使用 client.add_cog

    下次,请检查您的代码。

    以下是一个关于齿轮的discord网站: https://discordpy.readthedocs.io/en/stable/ext/commands/cogs.html