Home > Blockchain >  Discord bot not responding Node.js V16.5
Discord bot not responding Node.js V16.5

Time:11-15

I tried all the tutorials, but my bot just does not respond to my commands in a Discord chat

Index.js

const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');


const rest = new REST({ version: '9' }).setToken('[bot token]');

(async () => {
  try {
    console.log('Started refreshing application (/) commands.');

    await rest.put(
      Routes.applicationGuildCommands([clinent id], [guild id]),
      { body: commands },
    );

    console.log('Successfully reloaded application (/) commands.');
  } catch (error) {
    console.error(error);
  }
})();

bot.js

const { DiscordAPIError } = require('@discordjs/rest');
const { Client, Intents } = require('discord.js');
const Discord = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
const token = 'token';
const prefix = '!';

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`);
  console.log(``);
});

client.on('messageCreate', (message) => {
    if(message.content.toLowerCase().includes('hey bot') || message.content.toLowerCase().includes('general kenobi')){
        message.channel.send('Hello there!');
    }
});

client.on('messageCreate', (message) => {
    if(message.content.toLowerCase().includes('fudge') || message.content.toLowerCase().includes('pudding')){
        message.channel.send('Such language is prohibited!');
    }
});

client.login(token);

When I type any of the commands, the Discord bot just stays silent. I added bot.js as main in package.json.

I get no errors in the console.

CodePudding user response:

Those intents cover only operations with guild, not messages if I'm not wrong. You need GUILD_MESSAGES, and maybe even DIRECT_MESSAGES intent as well.

https://discord.com/developers/docs/topics/gateway#list-of-intents

CodePudding user response:

I find the cause. Apparently i had to check all the permissions my bot needed from developers section in discord. No tutorial showed that. And after that, I put more intents: Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILD_MESSAGES

enter image description here

  • Related