javascript - 是否可以在 js 中创建一个不和谐的机器人,从邀请链接或服务器 ID 获取服务器的成员数?
问题描述
所以我想用js做一个不和谐的机器人。如果您向机器人发送邀请链接,它应该能够告诉您服务器的成员数。可以这样编程吗?
解决方案
是的,您可以通过让机器人在加入后将公会中的所有用户放入一个数组并发送该数组的长度来做到这一点。
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);
推荐阅读
- python - ffmpeg如何将pcm编解码器标签添加到输出
- tensorflow - ML.NET 是否与 TF2 saved_model 格式兼容?
- postgresql - 将动态查询保存到 postgres 存储过程中的变量
- javascript - How to listen to the input event of the Stripe cardElement to determine if card is invalid and disable the button?
- html - 在 flexbox 中将图像居中
- python - 在python上保存变量的输入
- delphi - Retry after exception in delphi
- api - 如何制作侮辱命令(discord.py)
- html - 如何将 CSS 动画添加到 ReactJs 组件
- python - 使用字典将数据帧子集到多个