如何使用Discord机器人嵌入邮件? [英] How can I embed messages using a Discord bot?

查看:53
本文介绍了如何使用Discord机器人嵌入邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个可以将用户发送的消息嵌入特定频道的漫游器.如果您对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所说的那样,或使用

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机器人嵌入邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆