first of all, i make a telegram bot using python 3.10 with telegram.ext as module. i make a certain command can be run only with certain role. thus, i make a txt file for each role. so that command for example "/add_user" can only be run with "admin" role from admin.txt.
my problem is, i dont know how to add user from telegram. i want to make a command like:
/add_user george as admin <- this command will write george on admin.txt /add_user johnson as user <- this command will write johnson on user.txt
please help me.
this is part of my code:
from telegram.ext import *
import os
API_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
def start_command(update, context):
update.message.reply_text('Hello there! I\'m a very useful bot. What\'s up?')
def abs_command(update, context):
update.message.reply_text('ABS command is started . .')
os.system('python abs.py')
update.message.reply_text('ABS command is Finished . .')
def add_user_command(update, context):
# i dont know how to make command here
# Run the programme
if __name__ == '__main__':
updater = Updater(API_KEY, use_context=True)
dp = updater.dispatcher
# User List
user = open('./userlist/user.txt', 'r').read()
admin = open('./userlist/admin.txt', 'r').read()
dp.add_handler(CommandHandler('start', start_command, Filters.user(username=user)))
dp.add_handler(CommandHandler('start', start_command, Filters.user(username=admin)))
dp.add_handler(CommandHandler('abs', abs_command, Filters.user(username=absensak)))
dp.add_handler(CommandHandler('add_user', add_user_command, Filters.user(username=admin)))
# Run the bot
updater.start_polling(1.0)
updater.idle()