【发布时间】:2021-12-07 04:17:41
【问题描述】:
首先,我使用 python 3.10 和 telegram.ext 作为模块制作了一个电报机器人。 我使某个命令只能以特定角色运行。因此,我为每个角色制作了一个 txt 文件。因此,例如“/add_user”的命令只能以 admin.txt 中的“admin”角色运行。
我的问题是,我不知道如何从电报中添加用户。 我想做一个类似的命令:
/add_user george as admin
请帮帮我。
这是我的代码的一部分:
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()
【问题讨论】:
标签: python python-telegram-bot