gpt4 book ai didi

javascript - 检查 Discord.js DM 是否通过

转载 作者:行者123 更新时间:2023-12-02 02:40:03 25 4
gpt4 key购买 nike

我知道您可以发送这样的 DM:

message.author.send("Go to example.com for help");

但有些人的设置允许其他服务器成员通过 DM 关闭他们:

Screenshot of that option

如何查明 DM 是否实际发送?我知道这在 Discord API 中是可能的,因为其他机器人也这样做。

最佳答案

如果用户有该选项,或者不支持 DMable,则会抛出错误,即:

DiscordAPIError: Cannot send messages to this user   

现在,我们可以捕获该错误并基于它运行命令,例如在 channel 中回复用户无法通过 DMed。

user.send(...).catch(async err => message.reply("I can't DM this user"));
// In the above, async is useless, but you can actually do what you want with it.

要运行多行命令,请使用基于 Promise 的 catch。

user.send(...).catch(async err => {
console.log(err);
message.reply("I can't DM this user");
});

关于javascript - 检查 Discord.js DM 是否通过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63769474/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com