Error: No response from Twitch on tutorial

I’ve just started making Twitch bots, and I followed the tutorial on self-hosting the bot. I generated an oauth token and copied the files over from glitch.
My code:

const tmi = require("tmi.js");

// Define configuration options
const opts = {
  identity: {
    username: process.env.BOT_USERNAME,
    password: process.env.OAUTH_TOKEN
  channels: [process.env.CHANNEL_NAME]

// Create a client with our options
const client = new tmi.client(opts);

// Register our event handlers (defined below)
client.on("message", onMessageHandler);
client.on("connected", onConnectedHandler);

// Connect to Twitch:

// Called every time a message comes in
function onMessageHandler(target, context, msg, self) {
  if (self) {
  } // Ignore messages from the bot

  // Remove whitespace from chat message
  const commandName = msg.trim();

  // If the command is known, let's execute it
  if (commandName === "!d20") {
    const num = rollDice(commandName);
      `You rolled a ${num}. Link:`
    console.log(`* Executed ${commandName} command`);
  } else {
    console.log(`* Unknown command ${commandName}`);

// Function called when the "dice" command is issued
function rollDice() {
  const sides = 20;
  return Math.floor(Math.random() * sides) + 1;

// Called every time the bot connects to Twitch chat
function onConnectedHandler(addr, port) {
  console.log(`* Connected to ${addr}:${port}`);

I have installed tmi.js and all my credentials in the .env file are correct.

What is wrong?

There are many things this could be.

  • The host or ISP you are using blocks the IRC/Connection port you are using outbound
  • The username/password combination is invalid
  • Bad tmi.js version
  • Bad NodeJS version
  • Something else I’ve not thought of

You’ll need to add code to log the raw responses from Twitch