-2

I was trying to make a discord bot as a project and I’ve watched plenty tutorials but I couldn’t get it to work since it doesn’t detect messages and when it does detect is says (usernmame) said: ‘’

const Discord = require("discord.js");
const client = new Discord.Client({
    intents: [
        'GUILDS',
        'DIRECT_MESSAGES',
        'GUILD_MESSAGES'
    ],
    partials: ['MESSAGE', 'CHANNEL']
});

client.once('ready', () => {
    console.log(`Bot started as ${client.user.tag}!`);
});

client.on('messageCreate', message => {
    if (message.author.bot) return;

    const username = message.author.username;
    const userMessage = message.content;
    const channel = message.channel.name;

    console.log(`${username} said: '${userMessage}' (${channel})`);
    if (userMessage.toLowerCase() === 'hello') {
        message.channel.send(`Hey there, ${username}!`);
    }
});

const token = 'my token';
client.login(token);
  • 1
    Does this answer your question? [message.content doesn't have any value in Discord.js](https://stackoverflow.com/questions/73036854/message-content-doesnt-have-any-value-in-discord-js) – Zsolt Meszaros Jun 30 '23 at 17:19
  • As I mentioned in my linked answer, you'll need to add the `MESSAGE_CONTENT` intent too. – Zsolt Meszaros Jun 30 '23 at 17:19

1 Answers1

0

Discord has recently (over the last year or so) transitioned to preferring slash commands, which includes phasing out the use of message content. Consider migrating to slash commands in the future.

If you want to use message content, (as @Zsolt Meszaros said) you'll need to add the MESSAGE_CONTENT intent, as well as enabling it on the Bot tab of your application on the developer portal. It's worth noting that if your bot is in 100 or more guilds/servers, you'll need to apply for verification and be approved by Discord.

SkyBlu
  • 25
  • 1
  • 1
  • 8