如何创建一个有 memberCount 的机器人状态?

编程入门 行业动态 更新时间:2024-10-25 18:26:25
本文介绍了如何创建一个有 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用户,所以这是错误的方式,因为在机器人启动时,您将在此集合中没有用户.

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

  • 通过 ID 获取您的公会
  • 获取属性guild.memberCount
  • 每 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:

  • Get your guild BY ID
  • Get property guild.memberCount
  • 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 的机器人状态?

    本文发布于:2023-11-06 21:45:49,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1564761.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:创建一个   机器人   状态   memberCount

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!