0

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: []
  }
}

1 Answer 1

1

Rookie error, you try sending embed before it's defined:

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]});
Sign up to request clarification or add additional context in comments.

13 Comments

Don't you need content: " " for sending a message too?
content is not required whenever sending an embed on it's own
didn't really resolve the issue but thanks tho(I edited the message)
You sure? Every time when I tried to send an embed only (without content: " ") I got an Discord API Error - Cannot send empty message
@Toasty using 13.1.0 I've been able to send an embed without a content option. @some kid playing js what version of DJS are you running?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.