UNPKG

@nicat.dcw/discord-roles

Version:

🧃 Light Weight Discord Linked Roles Module with Discord API Interaction

31 lines (30 loc) • 1.13 kB
const storage = require("./storage") const push = require("./pushMetaData") module.exports = async (options = {}) => { const tokens = await storage.getDiscordTokens(options.userId); let metadata = {}; try { // Fetch the new metadata you want to use from an external source. // This data could be POST-ed to this endpoint, but every service // is going to be different. To keep the example simple, we'll // just generate some random data. metadata = { cookieseaten: 1483, allergictonuts: 0, // 0 for false, 1 for true firstcookiebaked: '2003-12-20', }; } catch (e) { e.message = `Error fetching external data: ${e.message}`; console.error(e); // If fetching the profile data for the external service fails for any reason, // ensure metadata on the Discord side is nulled out. This prevents cases // where the user revokes an external app permissions, and is left with // stale linked role data. } /* await pushMetaData({ userId: options.userId, body: options.body, id: options.id, token: options.tokens })*/ }