grammyjs / grammY

The Telegram Bot Framework.
https://grammy.dev
MIT License
2.04k stars 106 forks source link

Didn't receive any messages #612

Closed banx9x closed 2 weeks ago

banx9x commented 2 weeks ago

I’m learning to create my own bot. I’m following a tutorial in the documentation, but I don’t understand why it isn’t working.

Here is my code:

import { config } from "dotenv";
import { Bot } from "grammy";

// Load environment variables
config();

const bot = new Bot(process.env.BOT_TOKEN);

// Commands
bot.command("start", async (ctx) => {
  ctx.reply("Welcome! Up and running.");
});

// Messages
bot.on("message", (ctx) => {
  console.log(ctx);

  ctx.reply("Hmm");
});

// Start the bot (using long polling)
bot.start();

After running the bot, nothing happens when I send a message to it.

SCR-20240710-jevh
KnorpelSenf commented 2 weeks ago

Set DEBUG and see what is logged.

export DEBUG='*'
banx9x commented 2 weeks ago

Set DEBUG and see what is logged.

export DEBUG='*'

I discovered the error was due to Node version 21, I used version 18 and it worked. But strangely, no errors were printed, including the DEBUG set

KnorpelSenf commented 2 weeks ago

There is a bug in Node>18 that it can't perform network requests reliably if the ping is higher than 250 ms. Using Node 18 will work.