jufdnhf
(jufdnhf)
February 22, 2020, 6:25am
#1
Hello,
Currently I’m trying to add a function in my discord bot (js) that shows the amount of members in a certain group. After a bit of searching, all I could find is this API. Does anyone know how to use it with the bot?
Any help will be appreciated.
1 Like
Nitefal
(Nitefal)
February 22, 2020, 6:56am
#2
You can also strip the Html from the page which doesnt require an account or anything.
1 Like
jufdnhf
(jufdnhf)
February 22, 2020, 7:01am
#3
Thanks for the reply, I’m completely new at coding bots, so is it possible you could elaborate a bit?
1 Like
Nitefal
(Nitefal)
February 22, 2020, 7:06am
#4
I am currently not near my pc I will show an example when I can, if you don’t have another answer yet!
2 Likes
Affenity
(Visual)
February 22, 2020, 8:28am
#5
You just send the requests to the API. I can write you a little bot so you can understand it better.
const Discord = require("discord.js");
const request = require("request-promise");
const client = new Discord.Client();
client.login("token");
client.on("message", async message => {
const args = message.content.toLowerCase().split(/ +/g);
const command = args.shift();
if (command === "!membercount") {
const groupId = args[0];
if (!groupId) return message.reply("Specify a group id");
const groupData = await request(`https://groups.roblox.com/v1/groups/${groupId}`, {
json: true
});
return message.reply(`The group "${groupData.name}" has ${groupData.memberCount} members!`);
}
});
Naturally, you’d like to use a library for dealing with the API requests for simplicity, for example bloxy
3 Likes
jufdnhf
(jufdnhf)
February 22, 2020, 8:35am
#6
Hey, thanks for the reply, I’ve tried this and I’ve gotten this error, any idea why.
Affenity
(Visual)
February 22, 2020, 9:03am
#7
Have you defined “request”, in the error logs it seems like you haven’t.
1 Like
Make sure that you have ran the npm installer code for those
npm install request-promise
npm install discord.js
jufdnhf
(jufdnhf)
February 22, 2020, 8:23pm
#9
Alright, sorry for late reply, I did that and I got another error.
It can’t find the module request, so try also calling
npm install request
I get an response saying
The group "undefined" has undefined members!
eazoppe
(Eazoppe)
February 10, 2021, 11:26pm
#12
This is the line of code that I use for my bot to find the number of Members in a group.
I use the axios package to fetch the data from an API
const axios = require("axios");
await axios.get(`https://groups.roblox.com/v1/groups/${groupID}`).then(function (response) {
members = response.data.memberCount
});