【问题标题】:Is it possible to create a discord bot in js that gets the member count of a server from the invite link or the server Id?是否可以在 js 中创建一个不和谐的机器人,从邀请链接或服务器 ID 获取服务器的成员数?
【发布时间】:2020-05-15 23:14:40
【问题描述】:

所以我想在 js 中制作一个不和谐的机器人。如果您向机器人发送邀请链接,它应该能够告诉您服务器的成员数。可以这样编程吗?

【问题讨论】:

    标签: javascript discord discord.js


    【解决方案1】:

    是的,您可以通过让机器人在加入后将公会中的所有用户放入一个数组并发送该数组的长度来做到这一点。

    const Discord = require("discord.js");
    const bot = new Discord.Client();
    const token = 'YOUR_TOKEN';
    
    bot.on('guildCreate', guild => {
      //first the bot is going to find a channel to send the user count in
      let defaultChannel = "";
      guild.channels.forEach((channel) => {
        if (channel.type == "text" && defaultChannel == "") {
          if (channel.permissionsFor(guild.me).has("SEND_MESSAGES")) {
            defaultChannel = channel;
          }
        }
      })
      let arr = guild.members.array();
      defaultChannel.send(arr.length);
    
    });
    
    bot.login(token);
    

    【讨论】:

      猜你喜欢
      • 2021-04-22
      • 1970-01-01
      • 2018-08-05
      • 2021-01-04
      • 1970-01-01
      • 1970-01-01
      • 2021-08-26
      • 2021-09-13
      • 2020-12-02
      相关资源
      最近更新 更多