我正在使用此代码
client.on("messageCreate", async (message)=>{
if (message.content.includes("secret message")) {
message.author.send({embeds: [newEmbed]});
}
});
我希望机器人将此消息嵌入发送到用户的DM
这不是您的代码的问题。 发生这种情况是因为您的 Discord 帐户的 DM 已关闭。当您的 DM 关闭时,没有人可以向您发送消息,机器人也可以。
从
解锁您的 Discord DmSettings -> Privacy & Safety > Allow direct messages from server members
这应该可以解决您的问题,并考虑在代码中添加错误处理程序,如下所示:
client.on("messageCreate", async (message)=>{
if (message.content.includes("secret message")) {
try {
await message.author.send({embeds: [newEmbed]});
} catch(error) {
await message.reply({ content: "Cannot send the message as your dm is closed" });
}
}
});