owengombas / discord.ts

šŸ¤– Create your discord bot by using TypeScript and decorators!
https://owencalvin.github.io/discord.ts/
324 stars 40 forks source link

[Question] How to to send a MessageEmbed? #7

Closed KyleTryon closed 4 years ago

KyleTryon commented 4 years ago

Love the framework šŸŽ‰

I was hoping someone might be able to help me out in figuring out how to send a rich text or embedded message.

This appears to be the most up-to-date guide: https://discordjs.guide/popular-topics/embeds.html#embed-preview

Problem 1 I just discovered that even though I am installing "discord.js": "^12.1.1", I could see my type definition file was from 11.6.4 for some reason. I manually grabbed the updated one from GitHub.

That resolved my issues creating my MessageEmbed.

Problem 2

CommandMessage.reply would only accept a string as far as I understand, so post this MessageEmbed I believe we have to call CommandMessage.channel.send(), in there I sent my MessageEmbed.

When I test this, a post is made in the channel but it is a string, not an embedded message, and I am receiving this error:

 DiscordAPIError: Cannot send an empty message
    at /<my_project>/node_modules/@typeit/discord/node_modules/discord.js/src/client/rest/RequestHandlers/Sequential.js:85:15
    at /<my_project>/node_modules/snekfetch/src/index.js:215:21
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  name: 'DiscordAPIError',
  message: 'Cannot send an empty message',
  path: '/api/v7/channels/xxxxxxxxxxxxxxxx/messages',
  code: 50006,
  method: 'POST'
}

Answer: send({embed: MessageEmbed})

owengombas commented 4 years ago

Iā€™m happy that you found your answer, if you have any other issues just let me know :)