forked from projectdysnomia/dysnomia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
applicationCommands.js
101 lines (88 loc) · 4.12 KB
/
applicationCommands.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
const Dysnomia = require("@projectdysnomia/dysnomia");
const Constants = Dysnomia.Constants;
// Replace TOKEN with your bot account's token
const bot = new Dysnomia.Client("BOT TOKEN", {
gateway: {
intents: [] //No intents are needed for interactions, but you still need to specify either an empty array or 0
}
});
bot.on("ready", async () => { // When the bot is ready
console.log("Ready!"); // Log "Ready!"
const commands = await bot.getCommands();
if(!commands.length) {
bot.createCommand({
name: "test_chat_input",
description: "Test command to show how to make commands",
options: [ //An array of Chat Input options https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-structure
{
"name": "animal", //The name of the option
"description": "The type of animal",
"type": Constants.ApplicationCommandOptionTypes.STRING, //This is the type of string, see the types here https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-type
"required": true,
"choices": [ //The possible choices for the options
{
"name": "Dog",
"value": "animal_dog"
},
{
"name": "Cat",
"value": "animal_cat"
},
{
"name": "Penguin",
"value": "animal_penguin"
}
]
},
{
"name": "only_smol",
"description": "Whether to show only baby animals",
"type": Constants.ApplicationCommandOptionTypes.BOOLEAN,
"required": false
}
],
type: Constants.ApplicationCommandTypes.CHAT_INPUT //Not required for Chat input type, but recommended
}); //Create a chat input command
bot.createCommand({
name: "Test User Menu",
type: Constants.ApplicationCommandTypes.USER
}); //Create a user context menu
bot.createCommand({
name: "Test Message Menu",
type: Constants.ApplicationCommandTypes.MESSAGE
}); //Create a message context menu
bot.createCommand({
name: "test_edit_command",
description: "Test command to show off how to edit commands",
type: Constants.ApplicationCommandTypes.CHAT_INPUT //Not required for Chat input type, but recommended
}); //Create a chat input command
bot.createCommand({
name: "test_delete_command",
description: "Test command to show off how to delete commands",
type: Constants.ApplicationCommandTypes.CHAT_INPUT //Not required for Chat input type, but recommended
}); //Create a chat input command
//In practice, you should use bulkEditCommands if you need to create multiple commands
}
});
bot.on("error", (err) => {
console.error(err); // or your preferred logger
});
bot.on("interactionCreate", (interaction) => {
if(interaction instanceof Dysnomia.CommandInteraction) {
switch(interaction.data.name) {
case "test_edit_command":
interaction.createMessage("interaction recieved");
return bot.editCommand(interaction.data.id, {
name: "edited_test_command",
description: "Test command that was edited by running test_edit_command"
});
case "test_delete_command":
interaction.createMessage("interaction received");
return bot.deleteCommand(interaction.data.id);
default: {
return interaction.createMessage("interaction received");
}
}
}
});
bot.connect(); // Get the bot to connect to Discord