如何检查无效的用户 ID 和未禁止的用户

时间:2021-01-25 05:57:02

标签: javascript discord discord.js

我正在发出禁止命令并尝试检查输入是否为无效用户。然后,我尝试检查该用户是否有效,如果有效,请检查该用户是否未被禁止。

这是我与检查相关的代码:

const user = message.mentions.users.first() || await client.users.fetch(args[0]).catch(error => {
    return message.channel.send('Please enter a valid user.');
});
const checkBan = await message.guild.fetchBan(user.id).catch(error => {
    return null;
});
if (checkBan == null) {
    return message.channel.send('This user is already banned.');
}
if (!user) {
    return message.channel.send('Please specify a user.');
}

//output > "Please enter a valid user." & "This user is not banned."

如果您的输入不是有效用户,它会发送两个错误消息,如果用户有效并且被禁止,它可以正常工作。

所以我的问题是,如果用户无效,为什么会同时发送错误消息,我该如何解决该问题?

0 个答案:

没有答案