Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

291
Visualizações
DiscordAPIError, my Discordbot cannot embed

I am trying to program a discord chat bot, that when the command '!help' is directed to a certain text channel, the bot writes a direct message to the person who wrote the command in order to answer a series of questions, this is the code that I try:

const {Client, RichEmbed, Intents, MessageEmbed} = require('discord.js');
const bot = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.DIRECT_MESSAGES] });
 
const token = 'TOKEN';
 
const PREFIX = '!';
 
 
bot.on('ready', () => {
    console.log(`Logged in as ${bot.user.tag}!`);
})

bot.on('messageCreate', message => {
    let args = message.content.substring(PREFIX.length).split(" ");
    
    switch (args[0]) { 
        case 'help':
            const Embed = new MessageEmbed()
            .setTitle("Helper Embed")
            .setColor(0xFF0000)
            .setDescription("Make sure to use the !help to get access to the commands");
 
            message.author.send(Embed);
        break;
    }
 
});
                            
bot.login(token);

However, it throws me a DiscordAPIError error. Which is the following:

node_modules/discord.js/src/rest/RequestHandler.js:350
      throw new DiscordAPIError(data, res.status, request);
            ^

DiscordAPIError: Cannot send an empty message
    at RequestHandler.execute (/Users/mybot/node_modules/discord.js/src/rest/RequestHandler.js:350:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async RequestHandler.push (/Users/mybot/node_modules/discord.js/src/rest/RequestHandler.js:51:14)
    at async DMChannel.send (/Users/mybot/node_modules/discord.js/src/structures/interfaces/TextBasedChannel.js:176:15) {
  method: 'post',
  path: '/channels/98595393932745/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: []
  }
}
about 4 years ago · Santiago Gelvez
2 Respostas
Responde à pergunta

0

If I'm correct and you are using discord.js v13, you have to use message.author.send({embeds: [Embed]}) to send embeds!

about 4 years ago · Santiago Gelvez Relatório

0

In discord.js v13, you no longer send messages directly, you need to specify if its an embed, components etc. here's an example

message.author.send({content: 'you need help'}) // Normal message
message.author.send({embeds: [Embed]}) // embedded message
message.author.send({content: 'you need help', embeds: [Embed], components: [buttonRow]}) // To send message, embed and components

To make an interaction reply ephemeral, you use the same method, but boolean:

interaction.reply({embeds: [Embed], components: [row], ephemeral: true})
about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda