如何创建一个有 memberCount 的机器人状态? [英] How do I make a bot status that has memberCount on it?

查看:14
本文介绍了如何创建一个有 memberCount 的机器人状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个简单的不和谐验证机器人,但我想让机器人状态观看 # 人 验证(# 是我的服务器中有多少人).我看到一些机器人有它,但我不知道如何制作它.这是我当前的机器人状态代码:

if (Object.keys(this.config.presence).length !== 0) {this.user.setPresence({游戏: {名称:this.config.presence.name,类型:this.config.presence.type},状态:在线"}).catch(console.error);}

解决方案

首先你需要设置间隔命令来更新成员.

您不需要使用 this.user 进行此操作.以前的答案方法将仅显示 cached用户,所以这是错误的方式,因为在机器人启动时,您将在此集合中没有用户.

如果您需要在自己的服务器上显示成员,您可以这样做:

  1. 通过 ID 获取您的公会
  2. 获取属性guild.memberCount
  3. 每 5 分钟更新一次

client.on('ready', () => {setInterval(() => {targetGuild = client.guilds.get('GUILD ID HERE')如果(目标公会){client.user.setPresence({ game: { name: targetGuild.memberCount + 'people verifying!', type: 'WATCHING' }, status: 'online' }).then(console.log).catch(console.error);}}, 1000 * 60 * 5);});

<块引用>

bot 启动后,5 分钟后更新.

为了测试,您可以将 }, 1000 * 60 * 5) 更改为 }, 1000);

I made a simple discord verify bot, but I want to make the bot status to watching # people verifying (the # is how many people in my server). I see some bots have it, but I don't know how to make it. Here is my current code for the bot status:

if (Object.keys(this.config.presence).length !== 0) {
        this.user.setPresence({
            game: {
                name: this.config.presence.name,
                type: this.config.presence.type
            },
            status: "online"
        }).catch(console.error);
    }

解决方案

At the first you need set interval command to update member.

You dont need use this.user for this operation. The previus answer method will display only cached users, so its wrong way, because on bot start, you will has no users in this collection.

If you need display members on your own server you can do like this:

  1. Get your guild BY ID
  2. Get property guild.memberCount
  3. Update it every 5 min

client.on('ready', () => {
        setInterval(() => {
          targetGuild = client.guilds.get('GUILD ID HERE')
          if(targetGuild) {
              client.user.setPresence({ game: { name: targetGuild.memberCount + ' people verifying!', type: 'WATCHING' }, status: 'online'  })
                    .then(console.log)
                    .catch(console.error);
          }
    }, 1000 * 60 * 5);

});

After bot start, this will update after 5 minutes.

For test you can change }, 1000 * 60 * 5) to }, 1000);

这篇关于如何创建一个有 memberCount 的机器人状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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