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

我想编写一个将用户发送的消息嵌入特定频道的机器人。如果您对 GTA RP 服务器有所了解,它就像是 Twitter 或 Instagram 机器人。

这是一个例子:

http://img3.mukewang.com/641d6a730001d3c305921274.jpg

我认为这console.log与作者的名字有关,但我不确定,所以这就是我来这里的原因。我怎样才能像这样嵌入用户的消息?



蓝山帝景
浏览 214回答 3
3回答

慕少森

您可以使用 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 thingchannel.send({embeds: [embed]})channel.send({  embeds: [{    title: 'some title',    description: 'some description',    image: {url: 'image url'}  }]})// Discord.js v12// These two are the same thingchannel.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 toconst 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 ) 或上面链接的文档,以获取有关如何使用嵌入的更多信息。

子衿沉夜

此链接将带您进入在线嵌入工具,该工具可根据您的意愿和想法自动创建 Discord 嵌入。这当然可以帮助你。试试这个:-> https://autocode.com/tools/discord/embed-builder/

梵蒂冈之花

我认为你需要的是: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 此代码仅在您上传带有短信的图片时有效!
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript