DEV Community

Cover image for DJS Bot Template v2022.704.0 released!
Twiistrz
Twiistrz

Posted on

DJS Bot Template v2022.704.0 released!

Version 2022.704.0 has been released!

  • Update dependencies
  • Update readme (features)
  • New error process logger (e91d811):
...
import logger from './utils/logger.js';

...

process.on(`rejectionHandled`, (error) => logger.error(error));
process.on(`unhandledRejection`, (error) => logger.error(error));
process.on(`uncaughtException`, (error) => logger.error(error));
Enter fullscreen mode Exit fullscreen mode
import { Client, Interaction } from 'discord.js';
import { inject, injectable } from 'tsyringe';
import type { EventInterface } from '../client/interfaces/event.js';
import type { InteractionInterface } from '../client/interfaces/interaction.js';
import { INTERACTIONS } from '../client/tokens.js';
import logger from '../utils/logger.js';

@injectable()
export default class SelectMenuInteractionCreateEvent implements EventInterface {
    public name = `Select Menu Interaction Create`;
    public event = `interactionCreate`;

    public constructor(
        private readonly client: Client<true>,
        @inject(INTERACTIONS) private readonly interactions: Map<string, InteractionInterface>,
    ) {}

    public execute() {
        this.client.on(this.event, async (interaction: Interaction<`cached`>) => {
            try {
                if (!interaction.isSelectMenu()) {
                    return;
                }

                const menu_ = this.interactions.get(interaction.customId);

                if (!menu_) {
                    return;
                }

                await menu_.execute(interaction);
            } catch (e) {
                const error = e as Error;
                logger.error(error, error.message);
            }
        });
    }
}
Enter fullscreen mode Exit fullscreen mode
@@ -0,0 +1,22 @@
import type { SelectMenuInteraction } from 'discord.js';
import type { InteractionInterface } from '../client/interfaces/interaction.js';
import logger from '../utils/logger.js';

export default class ExampleSelectMenuInteraction implements InteractionInterface {
    public readonly name = `Example Select Menu`;
    public readonly customId = `selectMenuId`;

    public async execute(interaction: SelectMenuInteraction<`cached`>) {
        try {
            const values_ = interaction.values;

            await interaction.reply({
                content: `${values_.join(`\n`)}`,
                ephemeral: true,
            });
        } catch (e) {
            const error = e as Error;
            logger.error(error, error.message);
        }
    }
}
Enter fullscreen mode Exit fullscreen mode
  • Fixed eslint linter pattern (0d4f92f)
  • Fixed nullish or undefined in command-embed (329be04):
@@ -8,16 +8,18 @@ import config from '../../utils/config.js';
 * @returns {EmbedBuilder}
 */
export function exampleCommandEmbed(interaction: ChatInputCommandInteraction<`cached`>): EmbedBuilder {
    const options_ = interaction.options;

    const string_: string = options_.getString(`string`)!;
    const integer_: string = options_.getInteger(`integer`)?.toString() ?? `n/a`;
    const number_: string = options_.getNumber(`number`)?.toString() ?? `n/a`;
    const boolean_: string = options_.getBoolean(`boolean`)?.toString() ?? `n/a`;
    const user_: string = options_.getUser(`user`)?.toString() ?? `n/a`;
    const member_: string = options_.getMember(`user`)?.toString() ?? `n/a`;
    const channel_: string = options_.getChannel(`channel`)?.toString() ?? `n/a`;
    const role_: string = options_.getRole(`role`)?.toString() ?? `n/a`;
    const mentionable_: string = options_.getMentionable(`mentionable`)?.toString() ?? `n/a`;
    const choice_: string = options_.getString(`choice`) ?? `n/a`;

    return new EmbedBuilder()
        .setColor(config.color.primary)
    @@ -29,12 +31,12 @@ export function exampleCommandEmbed(interaction: ChatInputCommandInteraction<`ca
            { name: `String`, value: `${string_}`, inline: true },
            { name: `Integer`, value: `${integer_}`, inline: true },
            { name: `Number`, value: `${number_}`, inline: true },
            { name: `Boolean`, value: `${boolean_}`, inline: true },
            { name: `User`, value: `${user_}`, inline: true },
            { name: `Member`, value: `${member_}`, inline: true },
            { name: `Channel`, value: `${channel_}`, inline: true },
            { name: `Role`, value: `${role_}`, inline: true },
            { name: `Mentionable`, value: `${mentionable_}`, inline: true },
            { name: `Choice`, value: `${choice_}`, inline: true },
        );
}
Enter fullscreen mode Exit fullscreen mode

The full changelog is available on GitHub: 2022.704.0

Top comments (0)