B
B
bogdan99942021-04-10 23:32:08
Python
bogdan9994, 2021-04-10 23:32:08

How can I send a message when a command is executed, and send another message if the command fails?

We need code on the discord.py library, which will send messages depending on the execution / non-execution of the command.

For example, yes.
We have a code for banning a user on the server:

@bot.command(pass_contex=True)
@commands.has_permissions(administrator=True)
async def ban(ctx,member:discord.Member,*,reason=None):
    await member.ban(reason=reason)

If I, as an administrator, execute a command, the bot should write a message that the command was completed successfully.
Because of this line, the command will be executed:
@commands.has_permissions(administrator=True)

If the user tries to execute the command, the bot should reply that the command was not executed.

In general,
The command is running - a success message.
The command is not executed - a message about not executing.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Nevzorov, 2021-04-12
@bogdan9994

The command is being executed - message about successful execution.

@command(...)
...
async def cmd(ctx, *args):
    """Описание команды"""
    # делаем что-нибудь
    await ctx.send("Сделано!")

The command is not executed - a message about not executing.

https://discordpy.readthedocs.io/en/stable/ext/com...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question