ignshifts
ignshifts

Reputation: 101

Bot not responding to commands (discord.js v12)

I've tried doing a test command using client.on which worked but everything else in my command handler does not work. Nothing is returned, is there something I am doing wrong?

Issue: My ping command does not do anything whatsoever.

Index.js file

require('dotenv').config();
const Discord = require('discord.js');
const { Client, Collection, Intents } = require('discord.js');
const config = require('./config.json');
const fs = require("fs");
const client = new Client({ disableMentions: 'everyone', partials: ['MESSAGE', 'CHANNEL', 'REACTION'], ws: { intents: Intents.ALL } });
const PREFIX = config.PREFIX;
client.commands = new Discord.Collection();
const commandFiles = fs
  .readdirSync("./commands/")
  .filter((file) => file.endsWith(".js"));

  for (const file of commandFiles) {
    const command = require(`./commands/${file}`);
    client.commands.set(command.name, command);
  }
  
client.commands = new Collection();



Ping file

let config = require('../config.json');
const Discord = require('discord.js');
const { MessageEmbed } = require('discord.js');

module.exports = {
    name: 'ping',
    category: 'Info',
    description: 'Returns the bot\'s latency and API ping.',
    aliases: ['latency'],
    usage: 'ping',
    userperms: [],
    botperms: [],
    run: async (client, message, args) => {
        message.channel.send('🏓 Pinging....').then((msg) => {
            const pEmbed = new MessageEmbed()
                .setTitle('🏓 Pong!')
                .setColor('BLUE')
                .setDescription(
                    `Latency: ${Math.floor(
                        msg.createdTimestamp - message.createdTimestamp,
                    )}ms\nAPI Latency: ${client.ws.ping}ms`,
                );
            msg.edit(pEmbed);
        });
    },
};

Upvotes: 1

Views: 336

Answers (1)

Bimoware
Bimoware

Reputation: 1362

You need to add event which will trigger every time a message is created and the bot can see it.

An example on version 12 would be (using message :

client.on('message', message => {
  if (message.content.startsWith("!ping")) {
    message.channel.send('Pong!');
  }
});

In v13, message is deprecated so use messageCreate :

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

Upvotes: 2

Related Questions