node.js - 错误:[polling_error] {"code":"ETELEGRAM","message":"ETELEGRAM: 401 Unauthorized"}
问题描述
请帮我解决这个问题,我得到了 polling_error
我要在电报中创建一个机器人并为我自己定制它
但是当我运行程序时,我遇到了一些这样的错误:
node-telegram-bot-api deprecated 不推荐使用自动启用取消承诺。
和另一个这样的错误:
错误:[polling_error] {"code":"ETELEGRAM","message":"ETELEGRAM: 401 Unauthorized"}
我该如何解决这个问题?
完整的代码在这里:
const TelegramBot = require('node-telegram-bot-api');
const token = '***';
const bot = new TelegramBot(token, {polling: true});
bot.on('message', (msg) => {
let Hi = "hi";
if (msg.text.toString().toLowerCase().indexOf(Hi) === 0) {
bot.sendMessage(msg.chat.id,"Hello dear user");
}
});
解决方案
const TelegramBot = require('node-telegram-bot-api')
const Agent = require('socks5-https-client/lib/Agent')
const bot = new TelegramBot(process.env.TELEGRAM_API_TOKEN, {
polling: true,
request: {
agentClass: Agent,
agentOptions: {
socksHost: process.env.PROXY_SOCKS5_HOST,
socksPort: parseInt(process.env.PROXY_SOCKS5_PORT),
// If authorization is needed:
// socksUsername: process.env.PROXY_SOCKS5_USERNAME,
// socksPassword: process.env.PROXY_SOCKS5_PASSWORD
}
}
})
推荐阅读
- azure - Azure 应用程序洞察力。自定义属性长度限制
- c++ - std::string 类成员被第三方宏记录的字符串文字损坏
- rust - 为什么联合上的模式匹配会出现无法访问的模式警告?
- c++ - opencv desktop capture returns only part of the screen on windows in large fonts mode
- javascript - Match string entries by regexp and create splitted array in javascript
- node.js - Node.js AWS Lambda不一致s3.putObject上传大数据对象
- javascript - JQuery/CSS 气泡鼠标悬停
- python-3.x - Python - Check if String is in Dictionary Value when Value is a list
- ajax - 表单POST上的DoesNotExist异常后,同一页面上的Django ajax警告
- javascript - 控制器处的 MVC 空参数