0

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

Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132
  • 1
    Does this answer your question? [message.content doesn't have any value in Discord.js v14](https://stackoverflow.com/questions/73036854/message-content-doesnt-have-any-value-in-discord-js-v14) – Zsolt Meszaros Aug 31 '22 at 14:28

2 Answers2

2

Discord won't allow bots to read the messages anymore, unless you have a specific permission that is only granted to verified developers. The reason it doesn't work is probably because the rule is now effective.

Actually it's a permission to enable on the developer portal, my bad for this.

Although, the new way of creating commands are the slash commands. Discord.js provided a new guide, very complete on how to use them. They are recommended as they will allow you to do many more things

Note that you will have to register the commands when developing your bot.

nook
  • 1,729
  • 1
  • 12
  • 34
  • This isn't correct. You can still read message content - you just need to enable it in the dev portal as mentioned in DwarfDev's answer. See my answer to [this question](https://stackoverflow.com/questions/73542593/bot-does-not-receive-messages/73542771#73542771) for more details. – Joe Moore Aug 31 '22 at 14:54
  • Partly true, partly false, mostly false though. Bots will still be able to use the MessageContent intent, just not if they're in over 100 servers and not verified. – IDcLuc Aug 31 '22 at 15:22
1

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.

DwarfDev
  • 102
  • 5
  • I forgot to do that and didn't add commands to the bot permissions lol thanks –  Aug 31 '22 at 23:51