-1

So I'm following a YouTube toturial from 2021 on how to code a discord bot, beginner course. And im stuck on this one part of the tutorial that i can't get to work. I can't Get the bot to respond to my commands on Discord. If you know how to fix this i would appreciate the help, thx!

const Discord = require('discord.js');

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

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

const prefix = '!';

client.once('ready', () => {
    console.log('IamBot is online!');
});

client.on('message', message =>{
    if(!message.content.startsWith(prefix) || message.author.bot) return;

    const args = message.content.slice(prefix.length).split(/ +/);
    const command = args.shift().toLowerCase();

    if(command === 'ping'){
        message.channel.send('pong!');
    } else if (command == 'youtube'){
        message.channel.send('https://www.youtube.com/channel/UCPORwSx6_1e00INnAdrkDHg/videos');
    }
});

client.login('My Token Is Here');
IamAlbert
  • 1
  • 2
  • Discord.JS gets updated frequently. Consequently, video tutorials grow outdated very quickly. You have to include the `MessageContent` intent and enable the intent in your developer portal. I recommend sticking to the official guide and documentation in the future – Elitezen Oct 21 '22 at 22:19
  • 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 Oct 22 '22 at 20:29

1 Answers1

0

You need to add this to your intents.

GatewayIntentBits.MessageContent

It should look like this:

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

Also make sure to enable Message Content intent on the bot's Discord page. intent

EDIT:

client.on('message', message =>{

Should be

client.on('messageCreate', message =>{

As seen in the docs

Piecuu
  • 136
  • 1
  • 7