Home > Enterprise >  why won't discord chatbot in javascript respond?
why won't discord chatbot in javascript respond?

Time:09-22

I am working on this simple chatbot following the discord tutorial.

The chatbot has logged in to my server... I type in the chat room on Discord 'ping,' but the chatbot does not respond "Pong" as it should.

Below is the main,js code:

const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });

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

client.on('interactionCreate', async interaction => {
  if (!interaction.isCommand()) return;

  if (interaction.commandName === 'ping') {
      console.log("we got a hello!")
    await interaction.reply('Pong!');
  }
});

client.login('token');

NOTE: I have a secret token where it has 'token'

in my Terminal it says Logged in as Quote.it#4979! and my bot is online when I view it in the server in Discord.

But nothing happens when in discord I write in 'ping' Any way I can better diagnose what is going on?

Thank you

CodePudding user response:

I see a couple of problems here, first, it doesn’t look like you are registering the ping command see here, and second, you don’t have the right intents, you need the GUILD_MESSAGES one see here.

Here’s a simple ping pong bot:

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

const client = new Client({
    intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
    partials: ['CHANNEL', 'MESSAGE'],
})

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

client.on('messageCreate', (message) => {
    if (message.content.startsWith('ping')) {
        message.channel.send('pong!')
    }
})

client.login('token')
  • Related