A
A
Anastasia Sean2020-08-16 00:47:48
Python
Anastasia Sean, 2020-08-16 00:47:48

Access / Deny to the command?

Access and prohibition to the command. How to allow and forbid the user to use the selected command?
For example: I am allowed to use it, but others are not.
Besides, how to delete a command by a bot, after writing it?
Example: I wrote a command, after which the bot sent a message and deleted the command.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
I
Igromik, 2020-08-16
@x_shuziK_x

@Client.command(pass_context=True)
@commands.has_permissions(manage_messages=True)
async def ping(ctx):
  await ctx.message.delete()
  await ctx.send('Pong!')

A
alekssamos, 2020-08-16
@alekssamos

well, like

if  chat_id != admin_id: return False # только для админа

And the removal is usually MessageDeleteIf there is something like that.

Z
Zalim Lampezhev, 2020-08-17
@sabolch

Access and prohibition to the command. How to allow and forbid the user to use the selected command?
For example: I am allowed to use it, but others are not.

Add a condition where chat.id == '123456789' where '123456789' is your chat id.
if (total_say_ban > 0.80) and message.chat.id == 441945234:
            user_name = message.text.split('@')[1].strip()
            print(total_say_ban)

            # Бан пользователя>
            conn = sqlite3.connect("users.db")
            cursor = conn.cursor()

            # Находим ублюдка по его username, меняем значение rules на False
            sql = """
                        UPDATE white_list 
                        SET rules = 'False' 
                        WHERE user_name=?
                        """
            cursor.execute(sql, [user_name])
            fetch_id = cursor.fetchone()

            conn.commit()
            bot.send_message(user_id, f"Пользователь @{user_name} забанен.")

In my example, only I can ban a user. Or only a certain group of moderators (by adding their IDs to the condition). Well, or assign through a bot by writing the appropriate functionality)

W
wetwixs, 2020-08-20
@wetwixs

@client.command()
@commands.has_any_role( ID, ID, ID ) # ID роли, можно хоть сколько, можно хоть один
async def mute( ctx, member:discord.Member,time:int, * ,reason ):

U
UberPool, 2020-08-20
@UberPool

Use Decorators

@bot.command()
@commands.has_role(id_role) #id роли которой будет доступна эта команда
async def command(ctx):
    await ctx.message.delete()
      #делаешь что-то

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question