M
M
menma_uzumakie2022-02-19 01:19:16
Python
menma_uzumakie, 2022-02-19 01:19:16

The right to write a command only to the administrator?

How to make it so that only the admin has the right to write commands to the bot

import telebot

bot = telebot.TeleBot('my_token')

joinedFile = open('D:\\ras_bot\\joined.txt', 'r')
joinedUsers = set()
for line in joinedFile:
  joinedUsers.add(line.strip())
joinedFile.close()


@bot.message_handler(commands=['sub'])
def startJoin(message):
  if not str(message.chat.id) in joinedUsers:
    joinedFile = open('D:\\ras_bot\\joined.txt', 'a')
    joinedFile.write(str(message.chat.id) + '\n')
    joinedUsers.add(message.chat.id)

@bot.message_handler(commands=['send'])
def mess(message):
  for user in joinedUsers:
    bot.send_message(user, message.text[message.text.find(' '):])

@bot.message_handler(commands=["start"])
def start(m, res=False):
    bot.send_message(m.chat.id, 'Я на связи')

bot.polling(none_stop=True, interval=0)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
Gocha, 2022-02-19
@menma_uzumakie

Can also be used as an example

admin_keyboard = telebot.types.ReplyKeyboardMarkup(True)
admin_keyboard.row(" Купить")
admin_keyboard.row("ℹ️ Изменить FAQ ")

user_keyboard = telebot.types.ReplyKeyboardMarkup(True)
user_keyboard.row(" Купить", "ℹ️ FAQ")

and then with help reply_markupyou assign who can use the command. It's either admin_keyboard or user_keyboard.row
also using the command You forbid the use of the command ["ℹ️ Edit FAQ ",] user_keyboard.row The code looks like thisignor_command = ["ℹ️ Изменить FAQ ",]
admin_keyboard = telebot.types.ReplyKeyboardMarkup(True)
admin_keyboard.row(" Купить", "ℹ️ FAQ")
admin_keyboard.row("ℹ️ Изменить FAQ ")

user_keyboard = telebot.types.ReplyKeyboardMarkup(True)
user_keyboard.row(" Купить", "ℹ️ FAQ")
ignor_command = ["ℹ️ Изменить FAQ "]

M
makag, 2022-02-19
@makag

respond to commands only if the sender is an admin.
those. find out your telegram id
and respond to commands if the message parameter ['message']['from']['id'] is equal to your id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question