4
votes

I have discord server, and a website. On the website i would like to read a discord user's roles in a specific guild (My discord server) and display some content depending on their discord roles on my server. An example is checking whether a user has been whitelisted (Given a whitelist role).

I have tried to read the information via the normal API, but that is not possible. Instead i have tried to use a bot, but i do not see how i am able to access user information via the bot API. Can someone point me in the right direction, or help me? Thanks.

1
Use Discord's OAuth2 feature to get started, this should help: discordjs.guide/oauth2 - Octagonal T

1 Answers

1
votes

You can use express.js to do this, you don't really need to use OAuth2, unless you want to make a user specific dashboard (I suggest checking discordjs.guide/oauth2 as @Octagonal T suggested and this dashboard guide)

Code Example:

const Discord = require("discord.js");
const client = new Discord.Client();
const express = require('express');
const app = express();
const port = 80;

app.get('/', (req, res) => {
  let userList = bot.guilds.cache.get("guild id").members.cache.filter(member => {
      return member.roles.cache.some(r => "role id" === r.id)
   }).map(m => m.user.tag).join(', ');
  res.send(userList);
})

app.listen(port);

client.login("token");