我想编写一个可以将用户发送的消息嵌入特定频道的漫游器.如果您对GTA RP服务器一无所知,那就像是Twitter或Instagram机器人.
I want to code a bot that will embed a user's sent message in a specific channel. If you know anything about GTA RP servers, it's like a Twitter or Instagram bot.
这是一个例子:
我认为这与 console.log 和作者的名字有关,但是我不确定,所以这就是我在这里的原因.如何嵌入用户的消息,例如这个吗?
I think it's something about the console.log and the author's name, but I'm not sure so that's why I'm here. How can I embed users' messages like this?
推荐答案您可以使用 MessageEmbed ,就像programmergerRaj所说的那样,或使用 MessageOptions :
You can use a MessageEmbed, like programmerRaj said, or use the embed property in MessageOptions:
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 :
To send an embed of users' message in a particular channel, you can do something like this, where client is your 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) })请注意,以上代码将发送每条消息,而不是由僵尸程序发送的,因此您可能需要对其进行修改,以使其仅在需要时发送.
Note that the above code will send the embed for every message not sent by a bot, so you will probably want to modify it so that it only sends it when you want it to.
我建议您阅读 Discord.js嵌入指南( archive )或链接的文档上面提供了有关如何使用嵌入的更多信息.
I recommend reading Discord.js' guide on embeds (archive) or the documentation linked above for more information on how to use embeds.
更多推荐
如何使用Discord机器人嵌入邮件?
发布评论