Aircraft Overviewer
Aircraft Overviewer

Reputation: 55

Unable to send Embed in Discord.js master branch (v13)

Currently just playing with buttons in the master branch of discord.js, but I seem to be running into a problem. I can no longer send embeds using message.channel.send like I used to, and I always receive this error:

      throw new DiscordAPIError(data, res.status, request);
            ^

DiscordAPIError: Cannot send an empty message
    at RequestHandler.execute (C:\Users\%USERNAME%\Desktop\Arduino Projects\Discord Turret\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\%USERNAME%\Desktop\Arduino Projects\Discord Turret\node_modules\discord.js\src\rest\RequestHandler.js:50:14) {
  method: 'post',
  path: '/channels/750542030836334692/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
    },
    files: []
  }
}

The rest of the code runs fine, and sending regular strings is fine, but I cannot send an embed. If anyone has any advice for this, please let me know. Thanks!

require('dotenv').config();

const config = require('../config.json');
const { Client, MessageButton, Intents, MessageEmbed } = require('discord.js');

// Create new Client
const client = new Client({
    intents: [
        Intents.FLAGS.GUILDS,
        Intents.FLAGS.GUILD_MESSAGES,
        Intents.FLAGS.GUILD_INTEGRATIONS,
    ],
});

// Set Status
client.once('ready', () => {
    console.log('Discord Ready');
    client.user.setActivity('Arduino Uno', { type: 'LISTENING' });
});

// Create Buttons
const buttons = {
    up: new MessageButton()
        .setCustomId('up')
        .setLabel('⏫')
        .setStyle('PRIMARY'),
    down: new MessageButton()
        .setCustomId('down')
        .setLabel('⏬')
        .setStyle('PRIMARY'),
    left: new MessageButton()
        .setCustomId('left')
        .setLabel('⏪')
        .setStyle('PRIMARY'),
    right: new MessageButton()
        .setCustomId('right')
        .setLabel('⏩')
        .setStyle('PRIMARY'),
};

// Check Message Content
client.on('messageCreate', (message) => {
    if (!message.content.startsWith(process.env.PREFIX) || message.author.bot) return;

    const args = message.content.slice(process.env.PREFIX.length).trim().split(/ +/);
    const command = args.shift().toLowerCase();

    switch (command) {
        case 'up':
            const upEmbed = new MessageEmbed().setDescription('This is the up button');
            message.channel.send(controllerEmbed, buttons.up);
            break;
    }
});

// Login to Bot
client.login(process.env.TOKEN);

Upvotes: 0

Views: 679

Answers (1)

Aircraft Overviewer
Aircraft Overviewer

Reputation: 55

Figured it out. The embed must be specified and in an array. For anyone wondering, this is how the embeds now send:

const upEmbed = new MessageEmbed().setDescription('This is the up button');
message.channel.send({ embeds: [upEmbed] }, buttons.up);
break;

Upvotes: 2

Related Questions