N
N
NekIT2021-09-26 13:28:46
Python
NekIT, 2021-09-26 13:28:46

Discord bot. What is the problem?

I am making a bot that will ban people on command with a cooldown of 1 hour and only members with a certain role can ban.

@commands.has_role('1')
async def ban(ctx, member: discord.Member, days=1):
    if member is None:
        await ctx.send(f'{error_emoji} **Пожалуйста, укажите пользователя!** {error_emoji}')
    else:
        try:
            await Bot.ban(member, delete_message_days=0)
            await ctx.send('User banned for **' + str(days) + ' day(s)**')
            ban_list.append(member)
            day_list.append(days * 24 * 60 * 60)
            server_list.append(ctx.message.server)
        except:
            await ctx.send('Error! User not active')
        await ctx.send('You do not have permission to ban users!')


Instead of banning the command -ban @iSovBot 2 responds with this:
61504b1082c3f313489042.png

What's wrong? I gave myself the role, put the role of the bot above all, and still ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
Hawchik_dev, 2021-09-26
@Hawchik_dev

You have not correctly specified the condition for the existence of the role.
Try this:

@commands.has_permissions(ban_members=True)
async def ban(ctx, member: discord.Member, days=1):
    if member is None:
        await ctx.send(f'{error_emoji} **Пожалуйста, укажите пользователя!** {error_emoji}')
    else:
        try:
            await ctx.guild.ban(member, delete_message_days=0)
            await ctx.send('User banned for **' + str(days) + ' day(s)**')
            ban_list.append(member)
            day_list.append(days * 24 * 60 * 60)
            server_list.append(ctx.message.server)
        except:
            await ctx.send('Error! User not active')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question