7.0.1 • Published 2 years ago

discord-sucrose v7.0.1

Weekly downloads
-
License
Apache-2.0 Licens...
Repository
github
Last release
2 years ago

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.

# 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

/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 command sucrose.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();

    /* ... */
  },
};
7.0.0

2 years ago

7.0.1

2 years ago

7.0.0-dev.17

2 years ago

7.0.0-dev.16

2 years ago

7.0.0-dev.19

2 years ago

7.0.0-dev.18

2 years ago

7.0.0-dev.11

2 years ago

7.0.0-dev.13

2 years ago

7.0.0-dev.12

2 years ago

7.0.0-dev.15

2 years ago

7.0.0-dev.14

2 years ago

7.0.0-dev.28

2 years ago

7.0.0-dev.27

2 years ago

1.0.0

2 years ago

7.0.0-dev.20

2 years ago

7.0.0-dev.22

2 years ago

7.0.0-dev.24

2 years ago

7.0.0-dev.23

2 years ago

7.0.0-dev.26

2 years ago

7.0.0-dev.25

2 years ago

7.0.0-dev.9

2 years ago

6.4.9-dev

2 years ago

6.4.11-dev

2 years ago

7.0.0-dev

2 years ago

6.4.8-dev

2 years ago

7.0.0-dev.6

2 years ago

7.0.0-dev.3

2 years ago

7.0.0-dev.4

2 years ago

7.0.0-dev.7

2 years ago

7.0.0-dev.8

2 years ago

7.0.0-dev.1

2 years ago

6.4.10-dev

2 years ago

6.4.12

2 years ago

6.4.5-dev

2 years ago

6.4.7

2 years ago

6.4.6

2 years ago

6.3.4-dev

2 years ago

6.4.2-dev

2 years ago

6.4.0-dev

2 years ago

6.3.2-dev

2 years ago

6.3.11-dev

2 years ago

6.3.14

2 years ago

6.2.1

2 years ago

6.3.15

2 years ago

6.2.3

2 years ago

6.2.2

2 years ago

6.3.14-dev

2 years ago

6.3.8-dev

2 years ago

6.3.6-dev

2 years ago

6.4.3-dev

2 years ago

6.4.1-dev

2 years ago

6.3.3-dev

2 years ago

6.3.10-dev

2 years ago

6.4.4

2 years ago

6.3.1-dev

2 years ago

6.3.12-dev

2 years ago

6.3.13-dev

2 years ago

6.3.0-dev

2 years ago

6.3.9-dev

2 years ago

6.2.1-dev

2 years ago

6.3.7-dev

2 years ago

6.3.5-dev

2 years ago

6.2.0-dev

2 years ago

6.1.6

3 years ago

6.1.5

3 years ago

6.1.0

3 years ago

6.1.2

3 years ago

6.1.1

3 years ago

4.1.30

3 years ago

4.1.31

3 years ago

4.1.32

3 years ago

4.1.38

3 years ago

4.1.39

3 years ago

4.1.34

3 years ago

4.1.35

3 years ago

4.1.37

3 years ago

4.2.5

3 years ago

4.2.4

3 years ago

4.2.1

3 years ago

4.2.0

3 years ago

4.1.27

3 years ago

4.1.28

3 years ago

4.1.29

3 years ago

4.1.25

3 years ago

5.0.4

3 years ago

5.0.3

3 years ago

5.0.2

3 years ago

5.0.1

3 years ago

5.0.0

3 years ago

6.0.1

3 years ago

6.0.0

3 years ago

6.0.3

3 years ago

4.2.7

3 years ago

6.0.2

3 years ago

4.2.6

3 years ago

4.2.9

3 years ago

4.2.8

3 years ago

4.2.20

3 years ago

4.2.21

3 years ago

4.2.22

3 years ago

4.2.23

3 years ago

4.2.24

3 years ago

4.3.2

3 years ago

4.1.41

3 years ago

4.3.1

3 years ago

4.2.10

3 years ago

4.1.42

3 years ago

4.2.11

3 years ago

4.1.43

3 years ago

4.3.3

3 years ago

4.2.12

3 years ago

4.1.44

3 years ago

4.3.0

3 years ago

4.1.40

3 years ago

4.2.17

3 years ago

4.1.49

3 years ago

4.2.18

3 years ago

4.2.19

3 years ago

4.2.13

3 years ago

4.1.45

3 years ago

4.2.14

3 years ago

4.1.46

3 years ago

4.2.15

3 years ago

4.2.16

3 years ago

4.1.48

3 years ago

4.1.16

3 years ago

4.1.17

3 years ago

4.1.18

3 years ago

4.1.14

3 years ago

4.1.15

3 years ago

4.1.22

3 years ago

4.1.23

3 years ago

4.1.24

3 years ago

4.1.13

3 years ago

4.1.12

3 years ago

4.1.11

3 years ago

4.1.10

3 years ago

4.1.6

3 years ago

4.1.5

3 years ago

4.1.4

3 years ago

4.1.2

3 years ago

4.1.1

3 years ago

4.1.0

3 years ago

4.0.31-dev

3 years ago

4.0.27-dev

3 years ago

4.0.25-dev

3 years ago

4.0.20-dev

3 years ago

4.0.11-dev

3 years ago

4.0.1-dev

3 years ago