标签: python-telegram-bot

无法将音频上传到 telegram 错误请求:无法获取 HTTP URL 内容

我有 mp3 的工作 url,并且我正在尝试通过此 url 将音频发送到 Telegram。它有时会起作用,但大多数时候都会出错

"A request to the Telegram API was unsuccessful. The server returned HTTP 400 
Bad Request. Response body:
[b'{"ok":false,"error_code":400,"description":"Bad Request: failed to get HTTP 
URL content"}']"
Run Code Online (Sandbox Code Playgroud)

我不明白为什么,因为我检查了大小和类型,一切都很清楚,我在 Telegram API 文档中找不到更多限制。谁知道错误原因是什么?

链接到 mp3 - http://data3.api.xn--41a.ws/vkp/cs9-5v4.userapi.com/p15/51bdb5ec5899ed.mp3

python-3.x telegram python-telegram-bot telegram-bot telegram-webhook

6
推荐指数
1
解决办法
6532
查看次数

PythonBot - 将参数传递给命令处理程序

我正在玩 Python Telegram Bot,我想将先前计算获得的参数传递给我的处理程序,例如:

def my_handler(bot, update, param):
    print(param)

def main():
    res = some_function()
    updater.dispatcher.add_handler(CommandHandler('cmd', my_handler))
Run Code Online (Sandbox Code Playgroud)

如何将参数传递给处理程序?

python python-telegram-bot telegram-bot

6
推荐指数
2
解决办法
8821
查看次数

CallbackQueryHandler() 不起作用

我正在尝试将 CallbackQueryHandler() 与我的机器人一起使用,但我无法使其适用于我的情况。我尝试的机器人代码与此示例相同:

def start(bot, update):
    keyboard = [[InlineKeyboardButton("Option 1", callback_data='1'),
                 InlineKeyboardButton("Option 2", callback_data='2')],
                [InlineKeyboardButton("Option 3", callback_data='3')]]

    reply_markup = InlineKeyboardMarkup(keyboard)
    update.message.reply_text('Please choose:', reply_markup=reply_markup)

def button(bot, update):
    query = update.callback_query
    bot.edit_message_text(text="Selected option: %s" % query.data,
                          chat_id=query.message.chat_id,
                          message_id=query.message.message_id)
def help(bot, update):
    update.message.reply_text("Use /start to test this bot.")

def error(bot, update, error):
    logging.warning('Update "%s" caused error "%s"' % (update, error))

# Create the Updater and pass it your bot's token.
updater = Updater(TOKEN)
updater.dispatcher.add_handler(CommandHandler('start', start))
updater.dispatcher.add_handler(CallbackQueryHandler(button))
updater.dispatcher.add_handler(CommandHandler('help', help))
updater.dispatcher.add_error_handler(error)
# Start the Bot …
Run Code Online (Sandbox Code Playgroud)

python python-telegram-bot

6
推荐指数
1
解决办法
852
查看次数

如何发送带有标题/文本的电报媒体组

我目前正在使用python-telegram-bot,基本上我想用它实现的是发送这样的电报消息:

带有 3 张照片和标题的电报帖子

因此,该消息包含 2 张以上的照片/视频,下方带有文本消息。

我已经尝试过的:

  1. 使用send_message方法发送消息,并包括照片 URL,但它只显示文本下方的 1 张图片

  2. 使用send_media_group发送媒体组,但此方法没有caption作为send_photo 的参数。

python telegram python-telegram-bot telegram-bot

6
推荐指数
2
解决办法
7233
查看次数

urllib3 和 python-telegram-bot API 出现错误

当我尝试运行我的脚本(我的电报机器人)时,终端中会出现以下内容:

/usr/local/lib/python3.7/dist-packages/python_telegram_bot-12.4.2- 
py3.7.egg/telegram/utils/request.py:47: UserWarning: python-telegram-bot is using upstream urllib3. 
This is allowed but not supported by python-telegram-bot maintainers.
Run Code Online (Sandbox Code Playgroud)

我做什么?

多谢

python-3.x python-telegram-bot

6
推荐指数
1
解决办法
1875
查看次数

假装电报机器人正在打字?

如何让机器人假装正在输入消息?

当机器人假装打字时,聊天中会出现以下文本:

在此输入图像描述

我使用 python aiogram框架,但对本机 Telegram API 的建议也会有所帮助。

bots telegram python-telegram-bot

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

如何将 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
查看次数

类型错误:Updater.__init__() 得到意外的关键字参数“use_context”

当我执行此操作时发生了这种情况:

updater = Updater('xyaz:testtsttttt-HI', use_context=True)
Run Code Online (Sandbox Code Playgroud)

非常感谢!

python python-telegram-bot

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