I create a Discord bot using node.js. When I type node .
or node main.js
, my code is running without error and switches to online status in discord correctly, but the bot doesn't answer my commands. Bot has an administrator role on the server and all permissions.
My main code here:
const { Client, Intents, DiscordAPIError } = require('discord.js');
const { token } = require('./config.json');
Discord = require("discord.js")
const client = new Client({ intents: [32767]});
const prefix = '!';
const fs = require('fs');
client.commands = new Discord.Collection();
const commandFile = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFile) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.once('ready', () => {
console.log('Ready!');
})
client.on('messageCreate', 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') {
client.commands.get('ping').execute(message,args);
}
});
client.login(token);
And code my ping.js
from /commands/
here:
module.exports = {
name: 'ping',
description: "this is a ping command",
execute(message, args) {
message.channel.send('pong');
}
}