亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用 Discord 機器人嵌入消息?

如何使用 Discord 機器人嵌入消息?

藍山帝景 2023-03-24 17:16:07
我想編寫一個將用戶發送的消息嵌入特定頻道的機器人。如果您對 GTA RP 服務器有所了解,它就像是 Twitter 或 Instagram 機器人。這是一個例子:我認為這console.log與作者的名字有關,但我不確定,所以這就是我來這里的原因。我怎樣才能像這樣嵌入用戶的消息?
查看完整描述

3 回答

?
慕少森

TA貢獻2019條經驗 獲得超9個贊

您可以使用 a MessageEmbed,如 programmerRaj 所說,或使用embed以下屬性MessageOptions

const {MessageEmbed} = require('discord.js')


const embed = new MessageEmbed()

  .setTitle('some title')

  .setDescription('some description')

  .setImage('image url')


// Discord.js v13

// These two are the same thing

channel.send({embeds: [embed]})

channel.send({

  embeds: [{

    title: 'some title',

    description: 'some description',

    image: {url: 'image url'}

  }]

})


// Discord.js v12

// These two are the same thing

channel.send(embed)

channel.send({

  embed: {

    title: 'some title',

    description: 'some description',

    image: {url: 'image url'}

  }

})

要在特定頻道中發送嵌入的用戶消息,您可以這樣做,client您的 Discord.js 在哪里Client:


// The channel that you want to send the messages to

const channel = client.channels.cache.get('channel id')


client.on('message',message => {

  // Ignore bots

  if (message.author.bot) return

  // Send the embed

  const embed = new MessageEmbed()

    .setDescription(message.content)

    .setAuthor(message.author.tag, message.author.displayAvatarURL())

  channel.send({embeds: [embed]}).catch(console.error)

  // Discord.js v12:

  // channel.send(embed).catch(console.error)

})

請注意,上面的代碼將為不是由機器人發送的每條消息發送嵌入,因此您可能需要修改它,以便它僅在您需要時發送。

我建議閱讀Discord.js 的嵌入指南archive ) 或上面鏈接的文檔,以獲取有關如何使用嵌入的更多信息。


查看完整回答
反對 回復 2023-03-24
?
子衿沉夜

TA貢獻1828條經驗 獲得超3個贊

此鏈接將帶您進入在線嵌入工具,該工具可根據您的意愿和想法自動創建 Discord 嵌入。這當然可以幫助你。

試試這個:-> https://autocode.com/tools/discord/embed-builder/


查看完整回答
反對 回復 2023-03-24
?
梵蒂岡之花

TA貢獻1900條經驗 獲得超5個贊

我認為你需要的是:


const Discord = require('discord.js');


const client = new Discord.Client()


client.on("message", async message =>{


    if(message.author.bot) return;

    if(message.channel.id === 'channelID'){

        message.delete();

        const newEmbed = new Discord.MessageEmbed()

        .setAuthor(message.author.tag, message.author.displayAvatarURL())

        .setDescription(`${message.content}`)

        .setColor('#d32256')

        .setImage(message.attachments.first().proxyURL)

        .setTimestamp()

        .setFooter('Instagram', 'ImageOfInsta');

        message.channel.send(newEmbed);

    },

    });

其中 channelID 表示:您希望機器人重新發布的頻道和 ImageOfInsta:instagram 徽標的圖像!我通常先下載圖像或徽標,然后在 Discord 中重新上傳它。然后我在我的代碼中使用 Discord Image 的鏈接。


PS 此代碼僅在您上傳帶有短信的圖片時有效!


查看完整回答
反對 回復 2023-03-24
  • 3 回答
  • 0 關注
  • 437 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號