I am trying to host my telegram bot on Render. I am kinda new to programming so I apologize for any stupid code.
Im using VScode as editor and integrated terminal
When i host the bot locally with npm run dev through nodemon, everything works fine, but on Render I am treated with :
error code
/opt/render/project/src/node_modules/node-fetch/lib/index.js:1501
reject(new FetchError(request to ${request.url} failed, reason: ${err.message}
, ‘system’, err));
^
FetchError: request to https://api.telegram.org/bot7086599593:[REDACTED]/setMyCommands failed, reason:
at ClientRequest. (/opt/render/project/src/node_modules/node-fetch/lib/index.js:1501:11)
at ClientRequest.emit (node:events:518:28)
at TLSSocket.socketErrorListener (node:_http_client:500:9)
at TLSSocket.emit (node:events:518:28)
at emitErrorNT (node:internal/streams/destroy:169:8)
at emitErrorCloseNT (node:internal/streams/destroy:128:3)
at processTicksAndRejections (node:internal/process/task_queues:82:21)
at runNextTicks (node:internal/process/task_queues:64:3)
at listOnTimeout (node:internal/timers:540:9)
at process.processTimers (node:internal/timers:514:7) {
type: ‘system’,
errno: ‘ETIMEDOUT’,
code: ‘ETIMEDOUT’
}
I am new to all of the coding world, so I am not sure what I should attach, so here is my index.js and package.json
index.js
const { Telegraf, Extra } = require('telegraf');
const bot = new Telegraf('<My token>');
const { timeOptions, levOption } = require('./options.js');
const { DateTime } = require('luxon');
const { translate } = require('google-translate-api-browser');
const keep_alive = require('./keep_alive.js')
// get time
function getCurrentTime(timezone) {
return DateTime.now().setZone(timezone).toLocaleString(DateTime.TIME_24_SIMPLE);
}
const russiaTime = getCurrentTime('Europe/Moscow');
const indonesiaTime = getCurrentTime('Asia/Singapore');
// make words
let generate;
import('random-words').then(module => {
generate = module.generate;
});
//commands
bot.telegram.setMyCommands([
{ command: 'start', description: 'say hello' },
{ command: 'time', description: 'get times' },
{ command: 'lev', description: 'lev command' },
]);
//start
bot.start(ctx => {
ctx.reply(`some text`);
ctx.replyWithSticker('CAACAgIAAxkBAAEE4eNmJSOk67FOoiMUqzY-WHOh_2Pm8QACFQADwzrpMIiABX8lwyAmNAQ');
});
// lev options
bot.command('lev', (ctx) => {
ctx.reply('some text', levOption)
});
// lev reply
bot.action('levText', (ctx) => {
let randomAmount = Math.floor(Math.random() * 5) + 1 ;
let randomSentence = generate({ exactly: randomAmount, join: " " });
translate(`${randomSentence}`, { to: "ru" })
.then(res => {
ctx.reply(`some text, n${res.text}`);
})
});
//time options
bot.command('time', ctx => {
ctx.reply(`some text?`, timeOptions)
});
//time reply
bot.action("israel", ctx => {
ctx.reply(`some text, ${russiaTime}`);
});
bot.action("indonesia", ctx => {
ctx.reply(`some text, ${indonesiaTime}`);
});
bot.action("russia", ctx => {
ctx.reply(`some text, ${russiaTime}`);
});
bot.action("allcountries", ctx => {
ctx.reply(`some text, ${russiaTime},nа some text ${indonesiaTime}`);
});
bot.launch();
package.json
{
"name": "tgbot",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"google-translate-api-browser": "^5.0.0",
"luxon": "^3.4.4",
"node-fetch": "^2.6.1",
"random-words": "^2.0.1",
"telegraf": "^4.16.3"
},
"devDependencies": {
"nodemon": "^3.1.0"
},
"scripts": {
"test": "echo "Error: no test specified" && exit 1",
"dev": "nodemon index.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/SDX24/ovr-bot.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/SDX24/ovr-bot/issues"
},
"homepage": "https://github.com/SDX24/ovr-bot#readme",
"engines": {
"node": "20.12.2"
}
}
FYI: I the repository I am using is private, as there are my telegram bot tokens and I have removed some unnessesary comments and texts as they are written in a different language and shouldnt be affecting anything.
Thank you in advance!
I have tried to change versions of node-fetch and node as well as telegraf, tried implementing chatGPT written error catching and retry logic but am still getting the same issue.
I assume that the issue maybe related to me using telegraf as it has been one of the error parts when i tested previous code versions, but I think I fixed it.
Lhp is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.