javascript - DiscordJS 发送嵌入 DM
问题描述
我正在开发一个命令来 DM 特定用户嵌入,这是我项目中的帮助菜单。我成功发送了正常消息,但我不知道如何在 DM 中发送嵌入!,我读到它需要另一种类型的嵌入。
module.exports = {
name: 'costietare',
description: "This is a help command.",
async execute(client, message, args, Discord) {
message.delete({timeout: 10});
let dUser =
message.guild.member(message.mentions.users.first()) ||
message.guild.members.get(args[0]);
if (!dUser) return message.channel.send("Can't find user!");
if (!message.member.hasPermission('ADMINISTRATOR'))
return message.reply("Insufficient Permissions!");
let embed = new Discord.MessageEmbed()
.setTitle('General Information')
.setColor('YELLOW')
.addFields(
{name: 'Developer', value: '[m1](https://steamcommunity.com/id/catshvh)', inline:false},
{name: '!commands', value: 'More Commands & Usage for the bot', inline:true},
{name: 'BUY/Support', value: "[Click here to buy](https://discord.gg/4Qt3238jCy)", inline:true},
)
.setTimestamp()
dUser.send(`Sunt tare, stiu`); << Here is the normal message that its perfectly fine and
dUser.send(`${embed}`); << this reply with **[object Object]**
message.author.send(
`${message.author} You have sent your message to ${dUser}`
);
}
}
解决方案
假设您使用的是不和谐版本 12 或更低版本,请使用它来发送嵌入
const embed = new Discord.MessageEmbed().setDescription('test');
message.channel.send(embed);
// for users
dUser.send(embed); //
如果您使用的是不和谐版本 13
const embed = new Discord.MessageEmbed().setDescription('test');
message.channel.send({ embeds: [embed] });
//for users (dms)
dUser.send({ embeds: [embed] });
它发送对象范围又名 [object Object] 因为您将嵌入对象包装在模板文字${}
中,只需将嵌入对象作为普通参数传入,它应该可以工作
推荐阅读
- regex - elasticsearch 通配符正则表达式匹配特定模式
- python - 继承自 ABC 和 QMainWindow 的抽象类
- javascript - Material-UI 折叠表未正确渲染
- laravel - 我想用通配符 subdoamin 运行 socket.io 我该怎么做?
- java - 我怎么不能在最终结果中记录0
- python - 如何使用字典创建数据框并设置索引?
- javascript - Bootstrap Modal 中的 Codemirror 编辑器在单击之前不会加载内容
- css - 在 Bootstrap 4 中编写自定义实用程序类
- swift - 如何在 SwiftUI 中调整 SF Symbol 按钮的大小?
- firebase - 用户注册firebase的颤振问题