@sern/cli
Version:
Official CLI for @sern/handler
50 lines (49 loc) • 1.48 kB
JavaScript
// src/rest.ts
var baseURL = new URL("https://discord.com/api/v10/applications/");
var excludedKeys = /* @__PURE__ */ new Set(["command", "absPath"]);
var publishablesIntoJson = (ps) => {
const s = JSON.stringify(
ps.map((module) => module.data),
(key, value) => excludedKeys.has(key) ? void 0 : value,
4
);
return s;
};
var create = async (token) => {
const headers = {
Authorization: "Bot " + token,
"Content-Type": "application/json"
};
let me;
let appid;
try {
me = await fetch(new URL("@me", baseURL), { headers }).then((res) => res.json());
appid = me.id;
} catch (e) {
console.log("Something went wrong while trying to fetch your application:");
throw e;
}
const globalURL = new URL(`${appid}/commands`, baseURL);
return {
updateGlobal: (commands) => fetch(globalURL, {
method: "PUT",
body: publishablesIntoJson(commands),
headers
}),
getGuildCommands: (id) => {
const guildCommandURL = new URL(`${appid}/guilds/${id}/commands`, baseURL);
return fetch(guildCommandURL, { headers });
},
putGuildCommands: (guildId, guildCommand) => {
const guildCommandURL = new URL(`${appid}/guilds/${guildId}/commands`, baseURL);
return fetch(guildCommandURL, {
method: "PUT",
body: JSON.stringify(guildCommand),
headers
});
}
};
};
export { create };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=chunk-PAIOQOOR.js.map