简体   繁体   中英

Python discord bot, command not found

Why am I getting this error: Ignoring exception in command None: discord.ext.commands.errors.CommandNotFound: Command "Test" is not found

I saw other posts about this but the problem was them either not having their token or the bot.run(TOKEN) at the bottom

*EDIT Here's the updated code, still get the same error

import discord
from dotenv import load_dotenv
from discord.ext import commands

load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
GUILD = os.getenv('DISCORD_GUILD')

bot = commands.Bot(command_prefix='$', case_insensitive=True)

@bot.event
async def on_ready():
    for guild in bot.guilds:
        if guild.name == GUILD:
            break

    print(
        f'{bot.user} is connected to the following guild:\n'
        f'{guild.name}(id: {guild.id})'
    )

@bot.command()
async def on_message(ctx, arg):
    if ctx.author == bot.user:
        return
        
    if ctx.content.startswith('hello'):
        await ctx.channel.send(arg)

bot.run(TOKEN)


bot.run(TOKEN)

your code is basically right. There's a "spelling" mistake in the command that you wrote in the chat. You should use $test instead of $Test while entering the command. However, you can avoid these mistakes by setting case_insensitive to True

With your example it would look like this:

bot = commands.Bot(command_prefix='$', case_insensitive=True)

This should work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM