7.0.1 • Published 8 months ago

discord-sucrose v7.0.1

Weekly downloads
-
License
Apache-2.0 Licens...
Repository
github
Last release
8 months 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();

    /* ... */
  },
};
8.0.0-dev.gnL6HWXk

9 months ago

8.0.0-dev.aBn19FSU

9 months ago

8.0.0-dev.2hbwJgtL

9 months ago

8.0.0-dev.6E2b6E1w

8 months ago

8.0.0-dev.5bVHH4bX

9 months ago

8.0.0-dev.G9dySf4Q

9 months ago

8.0.0-dev.gvdb11GF

9 months ago

8.0.0-dev.B8n9hG6c

9 months ago

8.0.0-dev.z3DqmnpL

8 months ago

8.0.0-dev.J4PWbqS4

9 months ago

8.0.0-dev.7dqqnpLK

8 months ago

8.0.0-dev.TJzj4563

9 months ago

8.0.0-dev.qCXeb1XS

9 months ago

8.0.0-dev.5Q2vjcyN

9 months ago

8.0.0-dev.ZpL34uW7

9 months ago

8.0.0-dev.d6Erxe9u

9 months ago

8.0.0-dev.xKdVmU16

8 months ago

8.0.0-dev.FX62QbUC

9 months ago

8.0.0-dev.pTB8SaPw

9 months ago

8.0.0-dev.6qsGtemQ

9 months ago

8.0.0-dev.hzwGJ5sm

9 months ago

8.0.0-dev.fSThu5UR

8 months ago

7.0.0-dev.31d7jAdz

12 months ago

7.0.0-dev.fuV3fE1J

12 months ago

7.0.0-dev.AqkNpza6

12 months ago

7.0.0-dev.7ZtcMmPc

12 months ago

7.0.0-dev.QsN5bEJ5

12 months ago

7.1.0-dev.Zqad3a8m

12 months ago

7.0.0-dev.MGX6bkCe

12 months ago

7.0.0-dev.uSUb2zDF

12 months ago

7.0.0-dev.4TsFruq4

12 months ago

7.0.0-dev.SCw5w85d

12 months ago

7.1.0-dev.WCD6SwZ5

12 months ago

7.0.0-dev.bxRKJWe8

12 months ago

7.0.0-dev.m87ZNWMr

12 months ago

7.0.0

12 months ago

7.0.0-dev.ykNDK6EU

12 months ago

7.0.1

12 months ago

7.0.0-dev.17

12 months ago

7.0.0-dev.16

12 months ago

7.0.0-dev.19

12 months ago

7.0.0-dev.NTUV3eeS

12 months ago

7.0.0-dev.18

12 months ago

7.1.0-dev.Jk8phykC

12 months ago

7.0.0-dev.VLwfn6y8

12 months ago

7.0.0-dev.fJKCFxw3

12 months ago

7.0.0-dev.fjBj68Ht

12 months ago

7.0.0-dev.11

12 months ago

7.0.0-dev.13

12 months ago

7.0.0-dev.12

12 months ago

7.0.0-dev.15

12 months ago

7.0.0-dev.14

12 months ago

7.0.0-dev.28

12 months ago

7.0.0-dev.27

12 months ago

1.0.0

12 months ago

7.1.0-dev.hukyWW4w

12 months ago

7.0.0-dev.Y3j1YcKN

12 months ago

7.0.0-dev.L6RHdqz7

12 months ago

7.0.0-dev.gRg8VE6r

12 months ago

7.0.0-dev.20

12 months ago

7.0.0-dev.22

12 months ago

7.0.0-dev.24

12 months ago

7.0.0-dev.23

12 months ago

7.0.0-dev.26

12 months ago

7.0.0-dev.6bCkp9gt

12 months ago

7.0.0-dev.26WEX9dC

12 months ago

7.0.0-dev.25

12 months ago

7.0.0-dev.Ak4zPWXT

12 months ago

7.0.0-dev.LNj64fFq

12 months ago

7.0.0-dev.uLYPHbj6

12 months ago

7.0.0-dev.wQrf2mxJ

12 months ago

7.0.0-dev.9

12 months ago

7.0.0-dev.ETKu77R8

12 months ago

7.0.0-dev.Y6UjwzF8

12 months ago

7.1.0-dev.pNb3nLhR

12 months ago

7.0.0-dev.XB74abD9

12 months ago

6.4.9-dev

1 year ago

6.4.11-dev

1 year ago

7.0.0-dev

1 year ago

6.4.8-dev

1 year ago

7.0.0-dev.6

1 year ago

7.0.0-dev.3

1 year ago

7.0.0-dev.4

1 year ago

7.0.0-dev.7

1 year ago

7.0.0-dev.8

1 year ago

7.0.0-dev.1

1 year ago

6.4.10-dev

1 year ago

6.4.12

1 year ago

6.4.5-dev

1 year ago

6.4.7

1 year ago

6.4.6

1 year ago

6.3.4-dev

1 year ago

6.4.2-dev

1 year ago

6.4.0-dev

1 year ago

6.3.2-dev

1 year ago

6.3.11-dev

1 year ago

6.3.14

1 year ago

6.2.1

1 year ago

6.3.15

1 year ago

6.2.3

1 year ago

6.2.2

1 year ago

6.3.14-dev

1 year ago

6.3.8-dev

1 year ago

6.3.6-dev

1 year ago

6.4.3-dev

1 year ago

6.4.1-dev

1 year ago

6.3.3-dev

1 year ago

6.3.10-dev

1 year ago

6.4.4

1 year ago

6.3.1-dev

1 year ago

6.3.12-dev

1 year ago

6.3.13-dev

1 year ago

6.3.0-dev

1 year ago

6.3.9-dev

1 year ago

6.2.1-dev

1 year ago

6.3.7-dev

1 year ago

6.3.5-dev

1 year ago

6.2.0-dev

1 year ago

6.1.6

2 years ago

6.1.5

2 years ago

6.1.0

2 years ago

6.1.2

2 years ago

6.1.1

2 years ago

4.1.30

2 years ago

4.1.31

2 years ago

4.1.32

2 years ago

4.1.38

2 years ago

4.1.39

2 years ago

4.1.34

2 years ago

4.1.35

2 years ago

4.1.37

2 years ago

4.2.5

2 years ago

4.2.4

2 years ago

4.2.1

2 years ago

4.2.0

2 years ago

4.1.27

2 years ago

4.1.28

2 years ago

4.1.29

2 years ago

4.1.25

2 years ago

5.0.4

2 years ago

5.0.3

2 years ago

5.0.2

2 years ago

5.0.1

2 years ago

5.0.0

2 years ago

6.0.1

2 years ago

6.0.0

2 years ago

6.0.3

2 years ago

4.2.7

2 years ago

6.0.2

2 years ago

4.2.6

2 years ago

4.2.9

2 years ago

4.2.8

2 years ago

4.2.20

2 years ago

4.2.21

2 years ago

4.2.22

2 years ago

4.2.23

2 years ago

4.2.24

2 years ago

4.3.2

2 years ago

4.1.41

2 years ago

4.3.1

2 years ago

4.2.10

2 years ago

4.1.42

2 years ago

4.2.11

2 years ago

4.1.43

2 years ago

4.3.3

2 years ago

4.2.12

2 years ago

4.1.44

2 years ago

4.3.0

2 years ago

4.1.40

2 years ago

4.2.17

2 years ago

4.1.49

2 years ago

4.2.18

2 years ago

4.2.19

2 years ago

4.2.13

2 years ago

4.1.45

2 years ago

4.2.14

2 years ago

4.1.46

2 years ago

4.2.15

2 years ago

4.2.16

2 years ago

4.1.48

2 years ago

4.1.16

2 years ago

4.1.17

2 years ago

4.1.18

2 years ago

4.1.14

2 years ago

4.1.15

2 years ago

4.1.22

2 years ago

4.1.23

2 years ago

4.1.24

2 years ago

4.1.13

2 years ago

4.1.12

2 years ago

4.1.11

2 years ago

4.1.10

2 years ago

4.1.6

2 years ago

4.1.5

2 years ago

4.1.4

2 years ago

4.1.2

2 years ago

4.1.1

2 years ago

4.1.0

2 years ago

4.0.31-dev

2 years ago

4.0.27-dev

2 years ago

4.0.25-dev

2 years ago

4.0.20-dev

2 years ago

4.0.11-dev

2 years ago

4.0.1-dev

2 years ago