Integrating discord.js with Adonis.js

I need to create a bot for my discord channel.

I saw that discord make available a library Dicord.js

I would like to use AdonisJs to customize the conversation.

Is it possible to do this with Adonis?

1 Like

Yes it is possible as Discordjs is an NPM package.

1 Like

In server.js add preLoad

new Ignitor(require('@adonisjs/fold'))
  .appRoot(__dirname)
  .preLoad('start/bot')
  .fireHttpServer()
  .catch(console.error)

in start/bot.js

const { AkairoClient, CommandHandler } = require('discord-akairo');
const Env = use('Env')

class AnoregBot extends AkairoClient {
    constructor() {
        super({
            ownerID: '12345678910',
        }, {
            disableEveryone: true
        });
        this.commandHandler = new CommandHandler(this, {
            directory: 'app/Commands/',
            prefix: '!'
        });

        this.commandHandler.loadAll();
    }
}

const anoregBot = new AnoregBot();
anoregBot.login(Env.get('BOT_DISCORD_TOKEN'));

anoregBot.once("ready", () => {
    console.log(`Logged in as ${anoregBot.user.tag}!`)

})

//message.reply(`Me dá um segundo, não sei como está a conexão por lá`);

in app/Commands/test.js

const { Command } = require('discord-akairo');

class TestCommand extends Command {
    constructor() {
        super('test', {
            aliases: ['test', 'teste'],
            allowMention: true
        });
    }

    exec(message) {
        return message.reply('Está tudo bem!');
    }
}

module.exports = TestCommand;
1 Like

@LeCoupa my problem with not working was the version of the node.
Discord.js required node 12

1 Like