我知道您可以发送这样的DM:
message.author.send("Go to example.com for help");
但是某些人具有允许其他服务器成员将其DM关闭的设置:
如何确定DM是否实际发送?我知道在Discord API中这是可能的,因为其他机器人也可以做到这一点。
如果用户具有该选项,或者它不是DMable,它将引发错误,即:
DiscordAPIError: Cannot send messages to this user
现在,我们可以捕捉到该错误并运行基于该错误的命令,例如在无法进行用户DM的渠道中回复。
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.
要运行多个命令,请使用基于承诺的catch。
user.send(...).catch(async err => {
console.log(err);
message.reply("I can't DM this user");
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句