discord-sucrose v7.0.1
Discord bot structure using discord.js
Documentation here
Getting started
Click in "Use this template" and create your own repo
# Create your repository
On this example, we will start with the javascript template.
- Go to https://github.com/Natto-PKP/discord-sucrose-javascript-template
- Click 'Use template' button and create your repository
# Clone your repository
$ git clone app git@github.com:{userName}/{repositoryName}.git example-bot
$ cd example-bot && code .
# Create .env file
TOKEN='discord bot token'
Start bot with
npm start
# Install dependencies
npm install discord-sucrose discord.js dotenv
# Create .env file
TOKEN='discord bot token'
# Setup Sucrose structure
Create index.js
const { Sucrose } = require('discord-sucrose');
const { GatewayIntentBits, Partials } = require('discord.js');
require('dotenv').config();
Sucrose.build({ intents: [GatewayIntentBits.Guilds], partials: [Partials.Channel] });
Start bot with node index.js
Create a event
- Create a folder named "events", this one will contain all your events
- Create a folder named "ready" in the "events" folder, on this example we will base ourselves on the event ready
/events/ready/handler.js
/**
* @type { import('discord-sucrose').EventHandler<'ready'> }
*/
module.exports = ({ sucrose }) => {
console.log(sucrose.user.username + ' is online !');
};
Create a command
- Create a folder named "commands", this one will contain all your global and guilds commands
- Create a folder named "global" in the "commands" folder, on this example we will create a global command
- For a guild command, you must create a folder named "guilds" as well as a folder named with the id of the guild in question. For example:
/commands/guilds/713172382042423352
- For a guild command, you must create a folder named "guilds" as well as a folder named with the id of the guild in question. For example:
/commands/global/handler.js
const { ApplicationCommandType } = require('discord.js');
/**
* @type { import('discord-sucrose').ChatInput }
*/
module.exports = {
body: {
name: 'command',
type: ApplicationCommandType.ChatInput,
description: 'a command',
},
exec: async ({ interaction }) => {
await interaction.reply('I love ferret');
},
};
Easily place your command online in discord API with
sucrose.commands.define('command');
For guilds commandsucrose.commands.guilds.get('guildId').define('command');
Create a button
- Create a folder named "interactions" and in it, create a folder named "buttons". This last folder will contain your buttons
/interactions/buttons/use-me.js
const { ComponentType, ButtonStyle } = require('discord.js');
/**
* @type { import('discord-sucrose').Button }
*/
module.exports = {
data: {
type: ComponentType.Button,
customId: 'use-me',
style: ButtonStyle.Danger,
},
exec: ({ interaction }) => {
interaction.reply('Yeeaaaaah !');
},
};
Get your button with
sucrose.interactions.buttons.collection.get('use-me');
Create a select-menu
- Create a folder named "interactions" and in it, create a folder named "select-menus". This last folder will contain your select-menus
/interactions/select-menus/select-me.js
const { ComponentType } = require('discord.js');
/**
* @type { import('discord-sucrose').SelectMenu }
*/
module.exports = {
data: {
type: ComponentType.SelectMenu,
customId: 'select-me',
placeholder: 'Select me !',
options: [
{ label: 'I love ferret !', value: 'ferret' },
{ label: 'I love ferret !', value: 'ferret' },
{ label: 'I love ferret !', value: 'ferret' },
{ label: 'I love ferret !', value: 'ferret' },
{ label: 'I love ferret !', value: 'ferret' },
],
},
exec: ({ interaction }) => {
interaction.reply('I LOVE FERRET !!!');
},
};
Get your select-menu with
sucrose.interactions.selectMenus.collection.get('select-me');
Create a form modal
- Create a folder named "interactions" and in it, create a folder named "forms". This last folder will contain your form modals
/interactions/forms/report.ts
/**
* @type { import('discord-sucrose').Form }
*/
module.exports = {
data: {
customId: 'create-report',
title: 'Report ticket',
components: [
{
type: 'ACTION_ROW',
components: [
{
customId: 'report-reason',
type: 'TEXT_INPUT',
style: 'SHORT',
label: 'Indicate the reason for the report',
required: true,
},
],
},
{
type: 'ACTION_ROW',
components: [
{
customId: 'report-args',
type: 'TEXT_INPUT',
style: 'PARAGRAPH',
label: 'Indicate your problem',
required: true,
},
],
},
],
},
exec: ({ interaction }) => {
const reason = interaction.fields.getTextInputValue('report-reason');
const args = interaction.fields.getTextInputValue('report-args');
console.log(reason, args);
},
};
Get your form modal with
sucrose.interactions.forms.collection.get('report');
Create a autocompletion
- Create a folder named "interactions" and in it, create a folder named "autocompletions". This last folder will contain your autocompletion
/interactions/autocompletions/
/**
* @type { import('discord-sucrose').Autocomplete }
*/
module.exports = {
body: { command: 'image' },
exec: ({ interaction }) => {
const focus = interaction.options.getFocused();
if (focus === 'animals') {
/* ... */
} else if (focus === 'games') {
/* ... */
}
},
};
Autocompletion
/**
* @type { import('discord-sucrose').Autocomplete }
*/
module.exports = {
body: { command: 'image', option: 'animals' },
exec: ({ interaction }) => {
const focus = interaction.options.getFocused();
/* ... */
},
};
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago