Trying to make a discord bot that recieves info from a group

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

You can also strip the Html from the page which doesnt require an account or anything.

1 Like

Thanks for the reply, I’m completely new at coding bots, so is it possible you could elaborate a bit?

1 Like

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

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

Hey, thanks for the reply, I’ve tried this and I’ve gotten this error, any idea why.

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

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!

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
});