Ping Pong

Quack.js provides three options for reading in user input, slash commands, events, and triggers. Also, the events are expanded from Discord.js' base events utilizing the discord-logs package.

Slash Command

Slash commands are a handy feature of Discord, they provide an easy-to-use UI and awesome development features.

export default (Quack) => {
  Quack.CreateCommand({
    name: 'ping', // the name of the slash command
    description: 'Ping', // the description of the slash command
    permission: 'everyone', // the permission of the slash command, 
                            // if set to everyone then anyone can run it. 
                            // It can be set to a role id for specific role 
                            // use (make sure to set the defaultPermissions
                            // as well).
    guilds: ['728269506710995034'], // the guilds which the slash command 
                                    // will be added to. If none are added,
                                    // then it's a global command.
    execute(interaction) {
      interaction.reply('pong!')
    }
  })
}

And boom, you added your first slash command!

Events

Another way to create ping functionality is via events. You can simply do this y creating a messageCreate event, for example.

export default (Quack) => {
  Quack.CreateEvent({
    name: 'messageCreate',
    execute(client, message) {
      if (message.content.startsWith('ping')) {
        message.reply('pong')
      }
    }
  })
}

Triggers

Triggers are a handy little tool. If a regex or a normal string is met, the trigger will fire and you are able to perform an action.

export default (Quack) => {
  Quack.CreateTrigger({
    name: 'ping',
    trigger: 'ping',
    execute(client, message) {
      message.reply('pong')
    },
  })
}

Last updated