@nicat.dcw/discord-roles
Version:
🧃 Light Weight Discord Linked Roles Module with Discord API Interaction
67 lines (63 loc) • 1.66 kB
JavaScript
const { Client } = require("./index")
const express = require("express")
const app = express()
const client = new Client({
CLIENT_TOKEN:"",
CLIENT_ID: ""
})
client.add({
body: [
{
key: 'bakingsince',
name: 'Baking Since',
description: 'Days since baking their first cookie',
type: 6,
},
{
key: 'allergictonuts',
name: 'Allergic To Nuts',
description: 'Is Allergic To Nuts',
type: 7,
}
]
})/*.then(x => {
console.log(x.data)
})*/
app.get("/data", async (req,res) => {
res.json(client.getData())
client.storeDiscordTokens("31","32");
await client.pushMetaData({
userId: "31",
body: [{name:"31"}],
id: "31",
token: "31"
})
})
app.get('/linked-role', async (req, res) => {
const { url, state } = client.generateCallBack({
callback:"https://droles.greesybot.repl.co/linked-role"
});
// Store the signed state param in the user's cookies so we can verify
// the value later. See:
// https://discord.com/developers/docs/topics/oauth2#state-and-security
//res.cookie('clientState', state, { maxAge: 1000 * 60 * 5, signed: true });
// Send the user to the Discord owned OAuth2 authorization endpoint
res.redirect(url);
});
app.post('/update-metadata', async (req, res) => {
try {
const userId = req.body.userId;
// await clientpdateMetadata(userId)
await client.updateMetaData(userId)
await pushMetaData({
userId: "31",
metadata: [{name:"31"}],
id: "31",
token: "31"
})
res.sendStatus(204);
} catch (e) {
res.sendStatus(500);
}
});
app.listen(80)