D
D
Dima Remezkov2021-12-12 19:47:33
Python
Dima Remezkov, 2021-12-12 19:47:33

How to fix command not found error?

I’m sitting, cleaning up the chat, launching the bot and writing that the command was not found, although I even gave it a name.
Here is the code:

import discord      # импортируем нужные библиотеки, и токен для бота.
from discord.ext import commands
from discord.ext.commands import Bot
from config import TOKEN


bot = Bot(command_prefix='!')   # префикс бота перед командой

@bot.event
async def on_ready():
    print(f'Logged on {bot.user}')   # пишем что бот запустился

    await bot.change_presence(status=discord.Status.do_not_disturb, activity=discord.Game("!help")) # статус бота, и игра в которую он играет

@bot.command()
async def hi(ctx):
    await ctx.reply('Привет!') # первая команда, привет

@commands.command(name='clear')
async def clear(self, ctx, amount:int):
    messages = await ctx.channel.purge(limit = amount + 1)
    await ctx.send(f"{len(messages)} сообщений было очищено!")
 

bot.run(TOKEN)

Here is the error:
Logged on Leqort#9720
Ignoring exception in command None:
discord.ext.commands.errors.CommandNotFound: Command "clear" is not found

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
soremix, 2021-12-12
@SoreMix

Didn't create a team.
Either you do it simply @bot.command(), or @commands.command(), while registering it with bot.add_command(test).
@commands.command()yes, but no registration
https://discordpy.readthedocs.io/en/stable/ext/com...

W
Wolf_Yout, 2021-12-12
@Wolf_Yout

So the command is not created, or try:

@bot.command(name='clear')
async def _clear(self, ctx, amount:int):
    messages = await ctx.channel.purge(limit = amount + 1)
    await ctx.send(f"{len(messages)} сообщений было очищено!")

Or after bot = Bot(command_prefix='!') # bot prefix before the command write:
bot.add_command('clear')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question