M
M
maks_petrov92021-10-25 15:30:24
Python
maks_petrov9, 2021-10-25 15:30:24

How to make the discord.py bot write that he has no rights?

I am writing a bot for discord, for the test I created a command that gives a role to the user, and added the "command_error" event to it.

As planned, the bot will simply write that it does not have rights, but alas, it does not write this :s
I'm worried about this for a very long time , I look through the documentation of both discord and python itself a million times in search of an answer.

As a result, I turn to connoisseurs)


Code:

@Bot.command()
async def rtest(ctx, *, member = discord.Member, role = discord.Role):
  roll = discord.utils.get(ctx.guild.roles, id = role.id)

  await member.add_roles(roll)
  await ctx.send("+")

@rtest.error
async def rtest_error(ctx, error):
    if isinstance(error, commands.BotMissingPermissions):
        await ctx.send("I don't have sufficient permissions!")
    else:
        pass


I would be grateful for any help and answer!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-10-25
@Vindicar

Well for starters

async def rtest(ctx, *, member = discord.Member, role = discord.Role):

Not "=" but ":". This is a type hint , not a default value.
discord.py itself will convert the specified parameters into Member and Role objects.
So in theory it will be enough to write
await member.add_roles(role)
  await ctx.send("+")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question