1.0.0 • Published 2 years ago

@maclary/context v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Description

Context is a library that can convert Discord.js Messages or ChatInputs into a single, common, object that can be used to easily create slash and message commands without having to write code for each separately. Requires Discord.js >=14.0.0

@maclary/context is still in its early stages, please report any bugs or suggestions you may have.

Example

const { Context } = require('@maclary/context');

client.on('messageCreate', async (message) => {
    if (message.content !== '!hello') return;
    const context = new Context(message);
    return sharedRun(context);
});

client.on('interactionCreate', async (interaction) => {
    if (interaction.commandName !== 'hello') return;
    const context = new Context(interaction);
    return sharedRun(context);
});

async function sharedRun(context) {
    await context.deferReply();
    // interaction: `interaction.deferReply()`
    // message: `message.channel.sendTyping()`

    await context.editReply(`Hello ${context.user.username}`);
    // interaction: `interaction.editReply()`
    // message: `reply = message.reply()`

    await context.followUp(`How are you?`);
    // interaction: `interaction.followUp()`
    // message: `message.reply()`

    await context.editReply(`Bye ${context.author.username}`);
    // interaction: `interaction.editReply()`
    // message: `reply.edit()`

    await context.deleteReply();
    // interaction: `interaction.deleteReply()`
    // message: `reply.delete()`
}