dsc-utils | Documentation
The most easy way to handle discord interactions like dropdowns, buttons and slash commands
Last updated
The most easy way to handle discord interactions like dropdowns, buttons and slash commands
Last updated
Welcome 👋
Discord Profile Discord Server E-Mail GitHub
Here you have an example to create these components
const { Client } = require("discord.js")
const client = new Client()
const Utils = require("dsc-utils")
const utils = new Utils(client)
const token = "Your discord bot token" // https://discord.com/developers/applications
// Execute once the bot is logged in
client.on("ready", async () => {
console.log(client.user.tag)
// Create the command
const cmd = new utils.Command({
name: "welcome",
description: "Build a embed",
default_permission: true
})
// Create the options
const feeling = new utils.Option({
name: "feeling",
description: "How do you feel today",
type: "string"
})
// Add choices
feeling.setChoices([
new utils.Choice({
name: "Good",
value: "good"
}),
new utils.Choice({
name: "It's okay",
value: "okay"
}),
new utils.Choice({
name: "Not good",
value: "bad"
})
])
// Create one more option to test the ephemeral messages
const ephemeral = new utils.Option({
name: "ephemeral",
description: "Set the response to an ephemeral message",
type: "boolean"
})
// Add the options to the command
cmd.setOptions([
feeling,
ephemeral
])
// Create the global command
console.log(await utils.global().createCommand(cmd))
/**
* Discord is caching all global slash commands for 1 hour but to test the slash command immediately you need create a guild command:
*
* utils.guild("your guild id").createCommand(cmd)
*/
})
// Run once a slash command got executed
client.on("commandExecuted", cmd => {
console.log(cmd)
// Create a button
const button = new utils.Button({
label: "You're right",
style: "green",
ID: "my_id"
})
// Response to the interaction with the button
cmd.callback.post({
content: `You said you're feeling **${cmd.args.find(e => e.name == "feeling").value}**`,
components: [button],
ephemeral: cmd.args.find(e => e.name == "ephemeral").value
})
})
// Execute once a button got clicked
client.on("buttonClicked", btn => {
console.log(btn)
// Response to the button with a dropdown menu
btn.callback.post({
content: "Last component :)",
components: [
new utils.Dropdown({
placeholder: "Placeholder",
min: 0,
max: 3,
options: [
new utils.DropdownOption({
label: "Label 1",
value: "Value 1",
description: "Description"
}),
new utils.DropdownOption({
label: "Label 2",
value: "Value 2",
description: "Description",
default: true
}),
new utils.DropdownOption({
label: "Label 3",
value: "Value 3",
description: "Description"
})
],
ID: "lel"
})
]
})
})
client.on("dropdown", dropdown => {
console.log(dropdown)
// Response to the dropdown selection with the selected value
dropdown.callback.post(`You selected ${dropdown.values.map(e => `\`${e}\``).join(" ")}`)
})
client.login(token)