Giter Club home page Giter Club logo

djmtbot's Introduction

DJMTbot

A bot running Discord.js w/ Typescript, designed for the Pokemon Workshop Discord Server

Install Node.js

To use discord.js, you'll need to install Node.js here

Install Yarn

Install it here!

Install Dependencies

yarn 

Get a Discord Bot Token

To get your own bot token, create a bot!

You may also ask me for access to the PW Test server and dev bot token on Discord!

Create a .env file in the root directory

TOKEN and DEFAULT_PREFIX environment variables must be defined, one easy way to set them is by creating an .env file.

Your .env should look like this

TOKEN=YOUR_DISCORD_BOT_TOKEN_HERE
DEFAULT_PREFIX=djmt!

DO NOT COMMIT YOUR .ENV file to GIT. If you accidentally expose your token publicly, RESET THE TOKEN through the discord developer page ASAP!

Start the Bot

yarn start

Creating New Features (Components)

Visit ExampleComponentTemplate.ts for an example component template.

Copy and paste this file into the Components folder and implement your feature there. Make sure to read the comments throughly!

Saving and Loading Component Data

You will first need to define an interface of all the data you'd like to save. It is assumed that the data you define will to be able to be run through JSON.stringify() and JSON.parse() successfully

// Your components property in the guild json will be structured as defined here
interface ExampleComponentSave {
    channelId: string,
    width: number,
    height: number
}

When you've defined this interface, you must apply it to your Component as a generic through the <> syntax.

// Component<YOUR_INTERFACE_HERE> means your giving your interface to your class as a generic
export class DynamicBanner extends Component<ExampleComponentSave> {
  ...
}

The getSaveData function must return data as defined in your interface as this is what is written to the guild json.

async getSaveData(): Promise<ExampleComponentSave> {
    return {
        channelId: this.classChannelId,
        width: this.classWidth,
        height: this.classHeight
    };
}

Once getSaveData is properly defined, you can save your component's data to json at anytime by calling this.djmtGuild.saveJSON()

if (nextUrl) {
    this.classChannelId = "new channel";
    await this.djmtGuild.saveJSON(); // Save the component's current state to JSON
}

Data will load from the guild json everytime the bot starts up. Each component will receive its loaded data through the afterLoadJSON. You must handle the loadedObject yourself however you wish. You will most likely just be setting your components data.

async afterLoadJSON(loadedObject: ExampleComponentSave | undefined): Promise<void> {
    if (loadedObject) {
            // Set this components fields to the loaded data
            this.classChannelId = loadedObject.channelId;
            this.classWidth = loadedObject.width;
            this.classHeight = loadedObject.height;
    }
}

How you translate your component data to savable json data and and translate the loaded data back to your component data is entirely up to your implementation. I suggest looking into existing components saveJSON and afterLoadJSON implementation to see how this can be done.

If your data is not converting to JSON properly, consider modifying the JSON.stringify Replacer and JSON.parse Reviver functions to work for you.

Getting your component to run

You MUST add a line to export your Component class in index.ts for the bot to run your component!

// Component classes must be exported below to be run by the bot!
export { ExampleComponent } from './ExampleComponent';
export { AnotherComponent } from './AnotherComponent';
...

How To Contribute

Please branch off of the develop branch, and make Pull Requests to the develop branch for anything you'd like to contribute!

If you require more events, functions, or changes in anywhere, please make an issue for it!

Feel free to to contact me on discord for any help! DjMuffinTops#6590

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.