I was playing around with discord bot when my code is starting to get out of hand because there was too much code. So I decided to do some command handling.
First I tried to do it with my ping command but it didn't seem to work.
The main.js:
const config = require("./config.json");
const Discord = require('discord.js');
const { clientUser } = require("discord.js");
const clients = new Discord.Client({ intents: 14087});
const prefix = "-scp ";
var version = '1.6.6';
const packageJSON = require("./package.json");
const fs = require(`fs`);
const commandFiles= fs.readdirSync('./commands/')
.filter(file => file.endsWith('.js'));
for(const file of commandFiles){
const command = require(`./commands/${file}`);
clients.commands.set(command.name,command)
}
clients.on("messageCreate", (message) => {
try{
if( message.content == prefix + "ping" ){
clients.commands.get('ping').execute(message,args);
}
the file for "ping" is ping.js
const Discord = require("discord.js");
module.exports = {
name:'ping',
description:"ping command",
execute(message,args){
const embed = new Discord.MessageEmbed()
.setTitle("Pong! 🏓")
.setDescription("clients's latency: " +
`**${message.createdTimestamp - Date.now()}ms**` +
"\n" + `API's Latency: **${Math.round(clients.ws.ping)}ms**`)
.setColor('RANDOM');
channel.send({embeds: [embed]});
}
}
Error:
C:\Users\1love\Dropbox\My PC (DESKTOP-MEST1TS)\Desktop\Bot Core Assets\SCP bot assets\node_modules\discord.js\src\rest\RequestHandler.js:298
throw new DiscordAPIError(data, res.status, request);
^
> DiscordAPIError: Cannot send an empty message
at RequestHandler.execute (C:\Users\1love\Dropbox\My PC (DESKTOP-MEST1TS)\Desktop\Bot Core Assets\SCP bot assets\node_modules\discord.js\src\rest\RequestHandler.js:298:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (C:\Users\1love\Dropbox\My PC (DESKTOP-MEST1TS)\Desktop\Bot Core Assets\SCP bot assets\node_modules\discord.js\src\rest\RequestHandler.js:50:14)
at async TextChannel.send (C:\Users\1love\Dropbox\My PC (DESKTOP-MEST1TS)\Desktop\Bot Core Assets\SCP bot assets\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.js:171:15) {
method: 'post',
path: '/channels/417093499167440896/messages',
code: 50006,
httpStatus: 400,
requestData: {
json: {
content: undefined,
tts: false,
nonce: undefined,
embeds: undefined,
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: undefined,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined
},
files: []
}
}