如何解决如何使用Discord机器人嵌入邮件?
我想编写一个可以将用户发送的消息嵌入特定频道的漫游器。如果您对GTA RP服务器一无所知,那就像是Twitter或Instagram机器人。
这是一个例子:
我认为这与console.log
和作者的名字有关,但是我不确定,所以这就是我在这里的原因。如何嵌入用户的消息,例如
这个吗?
解决方法
您可以使用MessageEmbed
(例如,programmerRaj所说),也可以使用MessageOptions
中的embed
属性:
const {MessageEmbed} = require('discord.js')
const embed = new MessageEmbed()
.setTitle('some title')
.setDescription('some description')
.setImage('image url')
// 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(embed).catch(console.error)
})
请注意,以上代码将发送每条消息,而不是由僵尸程序发送的,因此您可能需要对其进行修改,以使其仅在需要时发送。
>我建议阅读Discord.js' guide on embeds(archive)或上面链接的文档,以获取有关如何使用嵌入的更多信息。
,我认为你需要的是:
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 的链接。
P.S 此代码仅在您上传带有短信的图片时有效!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。