Get All Users With a Role

In this guide, you will learn how to setup an API Request inside of BotGhost and get all of the users who have a specific role inside of your own personal Discord server from your bot!

To use our service, you firstly must have your own API key. Follow our Getting Your Key guide by clicking here to obtain one. It is completely free of charge to get create one!

1. Use the Send an API Request Block

First off, you need the "Send an API Request" from either your command or event builder.

2. Settings of the API Request

Once you have added the API Request block into your command or event builder, find the labeled section called Name, here you should insert the plain text of roles. This will allow you to reference the API Request in further actions.

After you have set the name of your request, click the "Request Builder" button. This will open up the builder of your request to our API, here you will need to add all of the required information.

Paste: https://api.erensko.xyz/v1/role-members to the URL at the top of the builder.

Once you have added the URL into your request's builder, find to the "URL Params" section and press the "Add" button so you have 2 sets of keys & values.

Once you're here, setup the keys and values for your URL Params, this is necessary.

Key
Value

role-id

The discord role ID to get the members of.

server-id

The discord server ID of where the role is.

After you have added your URL Params, it's time to finish the request by adding your HTTP Headers. Click on the "HTTP Headers" button and use the following set in the table. Your bot's token is required. To get your bot's token, you will need to reset it from the Discord Developer Portal. You also must have your own API key from us in order for you to send the request.

Key
Value

Authorization

Your own personal API key, create one by clicking here.

bot-token

The plain token of your Discord bot

3. Displaying Members

In order to display all the members who have the role, you can use the following BotGhost variables.

1. Ping all members with the role on a new line

{printAllValues([{roles.response.userIds}]),[<@$value>\n]}

2. Total count of members with the role (optional)

{roles.response.userCount}

Do you need any help? Feel free to join our Support Server by clicking here!

Last updated