LoginSignup
0
0

More than 3 years have passed since last update.

discord.jsでembed(埋め込み)を送りたい。

Posted at

discord.jsで埋め込みを送信したいと思います。
埋め込みのソースはこのような形になっております。

main.js
  if (message.content === 'ここのメッセージが送られたら反応する') {
try {
message.channel.send(
  {embed: {
    timestamp: new Date(),
    color: "RANDOM",
    description: `送るメッセージ`
  }}
);//送信
} catch (err) {//エラーが起きたら反応する。
      message.channel.send(
        {embed: {
    timestamp: new Date(),
    color: "RANDOM",
    description: "**エラー : 実行中にエラーが発生しました。**\n```js\n" + err + "```"
  }});//送信
    }}

これが埋め込みの基本的な形です。
さらに埋め込みにはメンションを加えることが出来ます。
しかし、通知はされません。

main.js
message.channel.send(
  {embed: {
    author: {
      name: "author name <@!496190049872773130>",
    },
    title: "title <@!496190049872773130>",
    description: "description <@!496190049872773130>",
    footer: {
      text: "footer text <@!496190049872773130>"
    },
    fields: [
      {
        name: "field name <@!496190049872773130>",
        value: "field value <@!496190049872773130>"
      }
    ]
  }}
);

を実行すると
画像.png
と表示されます。
つまり、descriptionとfield value以外はメンションが送られてません。

あとがき
embedのtestではembed-visualizerを利用しましょう。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0