mirror of
https://github.com/projectdysnomia/dysnomia.git
synced 2026-12-02 13:48:31 +02:00
This commit switches Dysnomia over to ESLint flat config for futureproofing and better maintainability. For the most part, the codebase will pass the test suite, apart from a few exceptions introduced by the stylistic plugin which I believe are reasonable to include. Additionally, JSDoc linting was added to maintain proper alignment of various features.
102 lines
4.1 KiB
JavaScript
102 lines
4.1 KiB
JavaScript
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
|