1

I'm making a discord bot, but I'm getting the error:

Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2).

I know something is wrong, but not sure what is it.

client.on('message', message => {
  if (message.content === 's!verifymsg') {
    const embed = new RichEmbed()
      .setTitle('__**VERIFICACIÓN**__')
      .setColor(0xFF0000)
      .setDescription('¡Para poder ver los demás canales, es necesario que reacciones para verificar! \n- Reacciona con (✅)')
    message.channel.send(embed);
  }
});

If you type s!verifymsg it sends an embed in that same channel containing some text in that same embed.

1 Answer 1

1

Looking at this guide (https://anidiots.guide/first-bot/using-embeds-in-messages), shows be that there are a couple things that might be causing it:

1) new RichEmbed() should probably be new Discord.RichEmbed(). This is what the discord.js documentation shows.

2) message.channel.send(embed); should probably be message.channel.send({embed});.

Sign up to request clarification or add additional context in comments.

4 Comments

You should probably expand out that last example to {embed: embed}. I dont think many people are familiar with the implicit behavior of wrapping an object in an object. plus a lot of the documentation explicitly uses embed: ...
@Marie I thought about it but wasn't sure of a good way to tie it back to the original code sample.
For this you have to understand node.js, in 1) you can do const { RichEmbed } = require('discord.js'); or const Discord = require('discord.js') for 2) (embed) alone should work as it will be handeld internally, obv {embed} will also work but {embed: embed} too because it renames embed to embed wich in this case doesn't matter but when you do const ExampleEmbed = new RichEmbed() you have to do .send('text ( optional) ', { embed: ExampleEmbed }); or .send(ExampleEmbed)
.send(embed) only works in the newer versions of discord.js tho so might do npm update

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.