Bot

Learn more about the Discord Bot

Introduction

Integrate a Discord bot to your gamemode can have some benefits for you. Creating a whitelist, use the awesome permission layer from Discord itself for in-game actions, read some server stats, kick players and so on. The list can go further.

Creating your own bot cannot be simpler than this.

Setup the Bot

Step 1

Go to https://discord.com/developers/applications and create an account and application if you do not already have on.

Step 2

Visit the Page Bot and Add Bot or use an existing one.

Step 3

Store the Bot Token inside your .env and set it up based on the picture below.

Step 4

Generate an OAuth URL and setup permissions for your bot, copy and paste it into your browser and invite the bot to your server.

That's all for the setup. The framework does the rest for you.

Example Usage

This example is not a real world example. It will only show you the usage with the decorator and the interaction with the bot. To keep it simple as possible, there is a decorator for you to interact with the discord bot events.

Any available bot event from discord.js are also useable with the decorator. The event params will be moved to the method.

Keep in mind, the decorator is only available server side

@Component()
export class MyComponent {

  /**
   * Do something if the guildMemberUpdate event fired
   *
   * @param {GuildMember} oldMember
   * @param {GuildMember} newMember
   */
  @OnDiscord('guildMemberUpdate')
  public doSomething(oldMember: GuildMember, newMember: GuildMember): void {
    // Now you can do something with the oldMember and the newMember
    // e.g. Check if a roles exists and kick if not
  }

}

Last updated