G
G
gfdsseg2021-08-15 19:02:19
Python
gfdsseg, 2021-08-15 19:02:19

An error in the discord bot code. How to do it right?

Mistake:

discord.ext.commands.errors.CommandRegistrationError: The command help is already an existing command or alias.


The code:

import discord
from discord.ext.commands import has_permissions
from discord.ext import commands

PREFIX = '&'

client = commands.Bot( command_prefix = PREFIX )


@client.event

async def on_ready():
    print( 'Bot connected' )


@client.command( pass_context = True )
@has_permissions( administrator = True )

async def clear( ctx, amount = 100 ):
    await ctx.channel.purge( limit = amount )


@client.command( pass_context = True )
@has_permissions( administrator = True )

async def kick( ctx, member: discord.Member, *, reason = None ):
    await ctx.channel.purge( limit = 1 )

    await member.kick( reason = reason )
    await ctx.send( f'kick user { member.mention }' )


@client.command( pass_context = True )
@has_permissions( administrator = True )

async def ban( ctx, member: discord.Member, *, reason = None ):
    await ctx.channel.purge( limit = 1 )

    await member.ban( reason = reason )
    await ctx.send( f'ban user { member.mention }' )


@client.command( pass_context = True )

async def help( ctx ):
    ebm = discord.Embed( title = 'Все наши команды' )

    emb.add_field( name = '{}help'.format( PREFIX ), value = 'Помощь по командам' )
    emb.add_field( name = '{}helpme'.format( PREFIX ), value = 'Помощь по командам в личку' )
    emb.add_field( name = '{}clear'.format( PREFIX ), value = 'очистка чата (только для админов)' )
    emb.add_field( name = '{}kick'.format( PREFIX ), value = 'кикнуть юзера (только для админов)' )
    emb.add_field( name = '{}ban'.format( PREFIX ), value = 'забанить юзера (только для админов)' )

    await ctx.send( embed = emb )


client.run( 'мой токен' )


if you pick up from discord.ext.commands import has_permissions then the error is this:

NameError: name 'has_permissions' is not defined

but I solved it: everything worked until I inserted it into the code:

from discord.ext.commands import has_permissions


@client.command( pass_context = True )

async def help( ctx ):
    ebm = discord.Embed( title = 'Все наши команды' )

    emb.add_field( name = '{}help'.format( PREFIX ), value = 'Помощь по командам' )
    emb.add_field( name = '{}helpme'.format( PREFIX ), value = 'Помощь по командам в личку' )
    emb.add_field( name = '{}clear'.format( PREFIX ), value = 'очистка чата (только для админов)' )
    emb.add_field( name = '{}kick'.format( PREFIX ), value = 'кикнуть юзера (только для админов)' )
    emb.add_field( name = '{}ban'.format( PREFIX ), value = 'забанить юзера (только для админов)' )

    await ctx.send( embed = emb )

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alan Gibizov, 2021-08-15
@phaggi

Translate the text of the error with Google and try to answer your own question.

B
Bot-Developer, 2021-08-16
@Bot-Developer

You could just translate the text of the error and understand what the problem is, but I will help. Add client.remove_command('help')
Full Code:

import discord
from discord.ext.commands import has_permissions
from discord.ext import commands

PREFIX = '&'

client = commands.Bot( command_prefix = PREFIX )


@client.event

async def on_ready():
    print( 'Bot connected' )


@client.command( pass_context = True )
@has_permissions( administrator = True )

async def clear( ctx, amount = 100 ):
    await ctx.channel.purge( limit = amount )


@client.command( pass_context = True )
@has_permissions( administrator = True )

async def kick( ctx, member: discord.Member, *, reason = None ):
    await ctx.channel.purge( limit = 1 )

    await member.kick( reason = reason )
    await ctx.send( f'kick user { member.mention }' )


@client.command( pass_context = True )
@has_permissions( administrator = True )

async def ban( ctx, member: discord.Member, *, reason = None ):
    await ctx.channel.purge( limit = 1 )

    await member.ban( reason = reason )
    await ctx.send( f'ban user { member.mention }' )


@client.command( pass_context = True )

async def help( ctx ):
    ebm = discord.Embed( title = 'Все наши команды' )

    emb.add_field( name = '{}help'.format( PREFIX ), value = 'Помощь по командам' )
    emb.add_field( name = '{}helpme'.format( PREFIX ), value = 'Помощь по командам в личку' )
    emb.add_field( name = '{}clear'.format( PREFIX ), value = 'очистка чата (только для админов)' )
    emb.add_field( name = '{}kick'.format( PREFIX ), value = 'кикнуть юзера (только для админов)' )
    emb.add_field( name = '{}ban'.format( PREFIX ), value = 'забанить юзера (только для админов)' )

    await ctx.send( embed = emb )


client.run( 'мой токен' )

Also, you could fix a bug with setting permissions for a command without a line. from discord.ext.commands import has_permissions
You could use @commands.has_permissions(administrator=True)instead@has_permissions(administrator=True)

Z
Zagir Majidov, 2021-08-17
@Zagir-vip

The help command is already there, here is the code, replace it with yours:
client = commands.Bot( command_prefix = PREFIX )
client.remove_command('help')
here is the better help command:

@client.command( pass_context = True )

async def help( ctx ):
    ebm = discord.Embed( title = 'Все наши команды' )

    emb.add_field( name = f'{ PREFIX }help',  value = 'Помощь по командам' )
    emb.add_field( name = f'{ PREFIX }helpme', value = 'Помощь по командам в личку' )
    emb.add_field( name = f'{ PREFIX }clear', value = 'очистка чата (только для админов)' )
    emb.add_field( name = f'{ PREFIX }kick', value = 'кикнуть юзера (только для админов)' )
    emb.add_field( name = f'{ PREFIX }ban', value = 'забанить юзера (только для админов)' )

    await ctx.send( embed = emb )

write to me on the discord and I'll show you a lot of things: Xpeawey#6098

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question