【问题标题】:How can i show an banlist from all banned users?如何显示所有被禁止用户的禁止列表?
【发布时间】:2019-11-12 01:34:29
【问题描述】:

我想创建一个类似 !banlist 的命令,然后我想显示被禁止用户的列表。如何在 NodeJS 和 discord.js 中做到这一点?

【问题讨论】:

  • 你不认为这个问题缺乏太多信息,不能成为一个实用的可回答问题吗?
  • 请阅读how to askmake a minimal example。你有什么尝试吗?你有代码要分享吗?你有不明白的错误吗? Stack Overflow 不是请为我写这篇文章网站

标签: javascript node.js discord.js


【解决方案1】:

Discord v13 更新

方法 guild.fetchBan(user) 现在在 v13 中为 guild.bans.fetch(user)。 同样方法 guild.fetchBans() 现在是 guild.bans.fetch()

interaction.guild.bans.fetch()
.then(bans => {
          
  let list = bans.map(user => user.user.username).join('\n');
    
  if (list.length >= 1950) list = `${list.slice(0, 1948)}`;
    
  interaction.followUp(`**${bans.size} users are banned:**\n${list}`);
})
.catch(console.error);

【讨论】:

    【解决方案2】:

    您可以使用Guild.fetchBans() 方法检索被禁止用户的Collection。请记住,它返回一个Promise

    message.guild.fetchBans()
      .then(banned => {
        let list = banned.map(user => user.tag).join('\n');
    
        // Make sure if the list is too long to fit in one message, you cut it off appropriately.
        if (list.length >= 1950) list = `${list.slice(0, 1948)}...`;
    
        message.channel.send(`**${banned.size} users are banned:**\n${list}`);
      })
      .catch(console.error);
    

    【讨论】:

      猜你喜欢
      • 2021-07-27
      • 2020-07-07
      • 1970-01-01
      • 2019-11-06
      • 1970-01-01
      • 2021-04-28
      • 2015-05-03
      • 2020-07-01
      • 2020-07-24
      相关资源
      最近更新 更多