Discord Bot 不发送 DM 消息

问题描述 投票:0回答:1

我正在使用此代码

client.on("messageCreate", async (message)=>{
  if (message.content.includes("secret message")) {
    message.author.send({embeds: [newEmbed]});
  }
});

结果我得到了一个错误,出了什么问题here is the error

我希望机器人将此消息嵌入发送到用户的DM

javascript discord discord.js
1个回答
0
投票

这不是您的代码的问题。 发生这种情况是因为您的 Discord 帐户的 DM 已关闭。当您的 DM 关闭时,没有人可以向您发送消息,机器人也可以。

解锁您的 Discord Dm

Settings -> 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" });
    }
  }
});
© www.soinside.com 2019 - 2024. All rights reserved.