MCPcopy Create free account
hub / github.com/discord/discord-example-app / createCommand

Function createCommand

examples/command.js:27–58  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

25});
26
27async function createCommand() {
28 const appId = process.env.APP_ID;
29
30 /**
31 * Globally-scoped slash commands (generally only recommended for production)
32 * See https://discord.com/developers/docs/interactions/application-commands#create-global-application-command
33 */
34 const globalEndpoint = `applications/${appId}/commands`;
35
36 /**
37 * Guild-scoped slash commands
38 * See https://discord.com/developers/docs/interactions/application-commands#create-guild-application-command
39 */
40 // const guildEndpoint = `applications/${appId}/guilds/<your guild id>/commands`;
41 const commandBody = {
42 name: 'test',
43 description: 'Just your average command',
44 // chat command (see https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-types)
45 type: 1,
46 };
47
48 try {
49 // Send HTTP request with bot token
50 const res = await DiscordRequest(globalEndpoint, {
51 method: 'POST',
52 body: commandBody,
53 });
54 console.log(await res.json());
55 } catch (err) {
56 console.error('Error installing commands: ', err);
57 }
58}
59
60app.listen(3000, () => {
61 console.log('Listening on port 3000');

Callers 1

command.jsFile · 0.85

Calls 1

DiscordRequestFunction · 0.90

Tested by

no test coverage detected