标签: python-telegram-bot

如何使用 telegram 内联机器人获取群组 ID 和聊天 ID?

你们有人知道@like telegram bot 是如何工作的吗?

当我使用内联在组中调用它,然后选择发布新帖子时,它会将我转发到机器人聊天,当我完成后,它会将我转发回我所在的组。所以它必须以某种方式拥有组 ID。

但根据 API 文档,这是不可能的。

我尝试了一些测试,我得到的只是用户 ID(作为聊天 ID)

我希望能够从组中调用内联机器人,然后使用用户 ID 和组 ID 将其转发到机器人聊天。@like 机器人似乎可以做到这一点,但我不知道如何做到。

有人能帮我吗?

api bots telegram python-telegram-bot telegram-bot

5
推荐指数
1
解决办法
6988
查看次数

使用 Telegram-InlineKeyboardMarkup,按下按钮时我可以向用户提供反馈吗?

def start(bot, update):
    keyboard = [[InlineKeyboardButton("Apples", callback_data='1')],
        [InlineKeyboardButton("Oranges", callback_data='2')],
        [InlineKeyboardButton("Beans", callback_data='3')],
        [InlineKeyboardButton("Rice", callback_data='4')],
        [InlineKeyboardButton("Bread", callback_data='5')],                
        [InlineKeyboardButton("Tomatos", callback_data='6')],                
        [InlineKeyboardButton("Strawberry", callback_data='7')]
    ]
    reply_markup = InlineKeyboardMarkup(keyboard)
    update.message.reply_text('Multiple choice Quizz \nSelect all vegetables:', reply_markup=reply_markup)
Run Code Online (Sandbox Code Playgroud)

使用 InlineKeyboardMarkup,是否有一种方法可以为用户按钮选择提供反馈,而无需隐藏或删除 InlineKeyboardMarkup?

例如,当用户选择 InlineKeyboardButton 时,我可以:

Change the InlineKeyboardButton text
Change the appearance of the InlineKeyboardButton
Edit initial message in update.message.reply_text ( )
Run Code Online (Sandbox Code Playgroud)

我想看看是否可以提出多项选择问题,如果可以,我需要提供一种方法让用户知道按钮已被选择或按下。

python telegram python-telegram-bot telegram-bot

5
推荐指数
1
解决办法
6744
查看次数

如何使用 python-telegran-bot sdk 在电报机器人中添加开始按钮?

我想使用python-telegram-bot SDK编写一个简单的电报机器人。我想显示“开始”键盘按钮,而不是键入“/开始”命令来与我的机器人一起工作。如何使用 python-telegram-bot 做到这一点?

python-telegram-bot telegram-bot

5
推荐指数
1
解决办法
8383
查看次数

如何通过 python-telegram-bot 发送照片

我希望代码在用户点击 /start 命令后发送照片,但它不起作用任何人都可以帮助我。谢谢

import emoji, telegram
from telegram.ext import Updater
from telegram.ext import CommandHandler, CallbackQueryHandler
from telegram import InlineKeyboardButton, InlineKeyboardMarkup

token = "-----------"
bot = telegram.Bot(token=token)

pic = "./photo.png"
try:
    chat_id = bot.get_updates()[-1].message.chat_id
except IndexError:
    chat_id = 0

#general functions
def start(bot, update):
    bot.send_photo(chat_id, pic)
    update.message.reply_text(text="helo",
                              reply_markup=menu_keyboard())
Run Code Online (Sandbox Code Playgroud)

python telegram python-telegram-bot telegram-bot

5
推荐指数
1
解决办法
1万
查看次数

在电报机器人中单击时如何更改内联按钮文本?

我在电报机器人创建方面还很陌生。我正在使用python-telegram-bot模块来构建电报机器人。我陷入了实现一个内联按钮的困境,该按钮在单击时会更改其文本。您能分享一些来源或方式吗?提前致谢。

简而言之,我的意思如下。例如,带有文本“1”的内联按钮,当我单击时我希望它更改为“2”。

def one(update, context):
    """Show new choice of buttons"""
    query = update.callback_query
    bot = context.bot
    keyboard = [
        [InlineKeyboardButton("3", callback_data=str(THREE)),
         InlineKeyboardButton("4", callback_data=str(FOUR))]
    ]
    keyboard[0][int(query)-1] = InlineKeyboardButton("X", callback_data=str(THREE))
    reply_markup = InlineKeyboardMarkup(keyboard)
    bot.edit_message_text(
        chat_id=query.message.chat_id,
        message_id=query.message.message_id,
        text="First CallbackQueryHandler, Choose a route",
        reply_markup=reply_markup
    )
    return FIRST
Run Code Online (Sandbox Code Playgroud)

python python-telegram-bot telegram-bot

5
推荐指数
1
解决办法
1万
查看次数

强制关闭电报上的弹出窗口“打开此链接?”

当我在帖子中使用 html 格式并创建链接时,Telegram在打开链接之前会显示一个弹出窗口。是否有脚本或其他东西可以强制关闭弹出窗口并立即打开链接?

我不想插入没有 HTML 的链接。

弹出电报

python telegram python-telegram-bot telegram-bot php-telegram-bot

5
推荐指数
1
解决办法
1777
查看次数

如何将 URL 添加到 Telegram Bot 的 InlineKeyboardButton

我想制作一个按钮,可以从 Telegram 聊天中在浏览器中打开 URL(外部超链接)。目前,我只开发了可点击的操作按钮。

update.message.reply_text(
    'Subscribe to us on Facebook and Telegram:',
    reply_markup=InlineKeyboardMarkup([
        [InlineKeyboardButton(text='on Facebook', callback_data='Facebook')],
        [InlineKeyboardButton(text='on Telegram', callback_data='Telegram')],
    ])
)
Run Code Online (Sandbox Code Playgroud)

但如何将它们作为链接(带箭头)。我想请求用户分享。

python python-telegram-bot telegram-bot

5
推荐指数
1
解决办法
2万
查看次数

ModuleNotFoundError:pip 安装后没有名为“telegram”的模块

运行后pip install python-telegram-bot,我收到此错误,表示找不到“电报”模块。

在下面pip list我看到我的 python-telegram-bot 软件包安装了版本 13.2

还有其他人收到此错误吗?

installation pip python-telegram-bot

5
推荐指数
1
解决办法
7088
查看次数

如何解决此错误:AttributeError:'NoneType'对象没有属性'reply_text'?

我有一个按钮,它应该返回ask_wikipedia函数,所以我使用了CallbackQueryHandler,但是当我想调用ask_wikipedia函数时,我收到一个属性错误!为什么?我该如何修复它?

def Click_Button(update, context) :
    query = update.callback_query
    if query.data == "Research":
        ask_wikipedia(update, context)

query_handler = CallbackQueryHandler(Click_Button)

dispatcher.add_handler(query_handler)



def ask_wikipedia(update, context)  :
    update.message.reply_text('What do you want to know about ? ')
    return About


Run Code Online (Sandbox Code Playgroud)

当我点击按钮时出现此错误

AttributeError: 'NoneType' object has no attribute 'reply_text'
Run Code Online (Sandbox Code Playgroud)

我该如何解决它?

python attributeerror telegram python-telegram-bot telegram-bot

5
推荐指数
1
解决办法
6096
查看次数

如何使用 Telegram 机器人发送文档?

我按照 youtube 上的教程学习了如何创建 Telegram Bot,目前它只能发送消息,但我什至想发送文档或音频、视频、照片等文件...现在我只是想发送一个文件,但我很困惑,我不知道该怎么做。

该机器人的源代码分为 2 个主要文件。一个responser.py:

def responses(input_text):
    user_message = str(input_text).lower()

    if user_message in ("test", "testing"):
        return "123 working..."
    

    return "The command doesn't exists. Type /help to see the command options."
Run Code Online (Sandbox Code Playgroud)

和main.py:

import constants as key
from telegram.ext import *
import responser as r

print("Hello. Cleint has just started.")

def start_command(update):
    update.message.reply_text("The Bot Has Started send you command sir.")



def help_command(update):
    update.message.reply_text("""
    Welcome to the Cleint Bot. For this purchase the following commands are available:
    send - send …
Run Code Online (Sandbox Code Playgroud)

python python-telegram-bot

5
推荐指数
1
解决办法
2万
查看次数