utarwyn / discord-tictactoe

Highly customizable innovative Discord Bot for playing Tic-Tac-Toe 🎮🏅
https://npmjs.com/package/discord-tictactoe
Apache License 2.0
99 stars 37 forks source link

Adding this commando project. #30

Closed critical58 closed 3 years ago

critical58 commented 3 years ago

I’ve been unable to add this to my bot using the commando framework, is this possible or am I doing something wrong?

utarwyn commented 3 years ago

Hello, I was not aware of the existence of this project, so i have not tested it yet. But I will check and get back to you soon!

utarwyn commented 3 years ago

I'm back to you with informations, @GDWingWangWong. Even if the support is not native, you can easily add your custom Commando command to start a TicTacToe game. Here is a sample of what I have done to make it works:

In your main file:

const path = require('path');
const Commando = require('discord.js-commando');

const client = new Commando.Client({
    owner: '...'
});

client.registry
    .registerDefaults()
    .registerCommandsIn(path.join(__dirname, 'commands'));

client.login('MY_BOT_TOKEN');

In the file commands/game/tictactoe.js:

const Command = require("discord.js-commando").Command;
const TicTacToe = require('discord-tictactoe');

module.exports = class TicTacToeCommand extends Command {
    constructor(client) {
        super(client, {
            name: 'tictactoe',
            group: 'commands',
            memberName: 'tictactoe',
            aliases: ['ttt'],
            description: 'Start a tictactoe game',
            clientPermissions: ['ADD_REACTIONS', 'MANAGE_MESSAGES', 'READ_MESSAGE_HISTORY', 'SEND_MESSAGES', 'VIEW_CHANNEL'],
            format: '[user]'
        })

        this.game = new TicTacToe();
    }

    async run(message) {
        this.game.handleMessage(message);
    }
}

You just have to create a TicTacToe instance (you can pass an object with options, see more info here) and use the method handleMessage(message) in the run(message) method. Is it ok for you?

critical58 commented 3 years ago

It works well! Thanks.