如何检查用户是否被禁止? [英] How do I check if a user is banned or not?

查看:75
本文介绍了如何检查用户是否被禁止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设法使unban命令起作用,但是现在我需要制定一个条件以避免错误,并且如果用户在禁止列表中,则需要将unban代码放入条件中,但是我不知道

解决方案

您可以使用 Guild.fetchBans() 进行检索被禁止用户的收藏。请记住,此方法返回承诺。然后,您可以使用 Collection。 find() 来搜索集合。



示例:



< pre class = lang-js prettyprint-override> //等待所需的异步上下文(这意味着它必须在异步函数中)。
//假设邮件是行会中的邮件。

try {
const banList = await message.guild.fetchBans();

const bannedUser = banList.find(user => user.id ==='someID');

如果(bannedUser)等待message.channel.send(`$ {bannedUser.tag}被禁止。);
else等等,等待message.channel.send(’该用户未被禁止。’);
} catch(err){
console.error(err);
}


I have managed to make the unban command to work, but now I need to make a condition to avoid errors, and need to put the unban code inside the condition if the user is in the ban list, but I have no idea how and haven't seen anything on internet.

解决方案

You can use Guild.fetchBans() to retrieve a Collection of banned users. Keep in mind, this method returns a Promise. You can then use Collection.find() to search through the Collection.

Example:

// Async context needed for 'await' (meaning this must be within an async function).
// Assuming 'message' is a Message within the guild.

try {
  const banList = await message.guild.fetchBans();

  const bannedUser = banList.find(user => user.id === 'someID');

  if (bannedUser) await message.channel.send(`${bannedUser.tag} is banned.`);
  else await message.channel.send('That user is not banned.');
} catch(err) {
  console.error(err);
}

这篇关于如何检查用户是否被禁止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆