Skip to content
Advertisement

Discord bot loading but commands are not working

I’m making my first Discord bot and I’m following this tutorial playlist here:

https://www.youtube.com/watch?v=j_sD9udZnCk&list=PLbbLC0BLaGjpyzN1rg-gK4dUqbn8eJQq4&ab_channel=CodeLyon

But for some reason my bot will load, say the load message, and even set its custom status but none of the commands are working. I have looked at many other forum posts and none are my problem so I’m very confused. I’m using Discord.js 14.3.0 and Node.js 16.17.0 on my Windows 10 machine. Here is my code:

const { Client, Discord, GatewayIntentBits } = require('discord.js');

const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
  ],
});

const token = ("REDACTED");
const prefix = '!';

client.once('ready', () => {
  console.log('Bot is online!')
  client.user.setActivity('Among Us');
});

client.on('message', message => {
  if (message.content === prefix + 'ping') {
    message.channel.send('Loading data').then(async(msg) => {
      msg.delete()
      message.channel.send(`Latency is ${msg.createdTimestamp - message.createdTimestamp}ms. API Latency is ${Math.round(client.ws.ping)}ms`);
    })
  }
});

client.login(token);

Also I have modified a few things and tried some other peoples code and I get no errors, it just won’t work

Advertisement

Answer

Bots now need a special intent to be able to read messages.

To activate the intent, first go to your Developer Portal, select your application and activate the Message Content Intent. Next add GatewayIntentBits.MessageContent to your intent list to be able to use it.

Note that if your bot is on 100 or more servers it needs to be verified in order to access intents. More information about the change can be found here.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement