Skip to content

Commit

Permalink
fix(#32): auto inject client in handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
barthofu authored and Mr-Artemus committed Aug 20, 2022
1 parent 04088c9 commit bb89831
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
14 changes: 8 additions & 6 deletions cli/generators/templates/command.ts.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@ import { Client } from "discordx"
import { Category } from "@discordx/utilities"
import { CommandInteraction } from "discord.js"

import { Discord, Slash, SlashOption } from "@decorators"
import { Discord, Slash } from "@decorators"
import { Guard } from "@guards"

@Discord()
@Category('{{pascalCase category}}')
export default class {{pascalCase name}}Command {

@Slash('{{camelCase name}}', { description:
'Here goes the command description!'
})
@Slash({
name: '{{camelCase name}}',
description: 'Here goes the command description!'
})
@Guard()
{{camelCase name}}(
async {{camelCase name}}(
interaction: CommandInteraction,
client: Client,
{ localize }: InteractionData
): void {
) {

interaction.reply('{{camelCase name}} command invoked!')
}
Expand Down
2 changes: 2 additions & 0 deletions src/commands/Admin/prefix.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Client } from "discordx"
import { Category } from "@discordx/utilities"
import { ApplicationCommandOptionType, CommandInteraction } from "discord.js"
import { injectable } from "tsyringe"
Expand Down Expand Up @@ -30,6 +31,7 @@ export default class PrefixCommand {
async prefix(
@SlashOption({ name: 'prefix', type: ApplicationCommandOptionType.String, required: false }) prefix: string | undefined,
interaction: CommandInteraction,
client: Client,
{ localize }: InteractionData
) {

Expand Down
6 changes: 5 additions & 1 deletion src/commands/General/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ export default class HelpCommand {
name: 'help',
description: 'Get global help about the bot and its commands'
})
help(interaction: CommandInteraction, client: Client, { sanitizedLocale }: InteractionData): void {
async help(
interaction: CommandInteraction,
client: Client,
{ sanitizedLocale }: InteractionData
) {

const embed = this.getEmbed({ client, interaction, locale: sanitizedLocale })

Expand Down
7 changes: 6 additions & 1 deletion src/commands/General/invite.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Client } from "discordx"
import { Category } from "@discordx/utilities"
import { CommandInteraction, EmbedBuilder } from "discord.js"

Expand All @@ -15,7 +16,11 @@ export default class InviteCommand {
description: 'A simple invite command!'
})
@Guard()
invite(interaction: CommandInteraction, { localize }: InteractionData): void {
async invite(
interaction: CommandInteraction,
client: Client,
{ localize }: InteractionData
) {

const embed = new EmbedBuilder()
.setTitle(localize.COMMANDS.INVITE.TITLE())
Expand Down
2 changes: 2 additions & 0 deletions src/commands/General/stats.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Client } from "discordx"
import { Category } from "@discordx/utilities"
import { CommandInteraction, EmbedBuilder, User } from "discord.js"
import { injectable } from "tsyringe"
Expand Down Expand Up @@ -57,6 +58,7 @@ export default class StatsCommand {
async statsHandler(
@SlashOption({ name: 'days' }) days: number,
interaction: CommandInteraction,
client: Client,
{ localize }: InteractionData
) {

Expand Down
6 changes: 4 additions & 2 deletions src/commands/Owner/maintenance.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Client } from "discordx"
import { CommandInteraction } from "discord.js"

import { Slash, Discord, SlashOption, Guard } from "@decorators"
import { setMaintenance, simpleSuccessEmbed } from "@utils/functions"
import { getLocaleFromInteraction, L } from "@i18n"
import { Disabled } from "@guards"
import { CommandInteraction } from "discord.js"

@Discord()
export default class MaintenanceCommand {
Expand All @@ -17,6 +18,7 @@ export default class MaintenanceCommand {
async maintenance(
@SlashOption({ name: 'state' }) state: boolean,
interaction: CommandInteraction,
client: Client,
{ localize }: InteractionData
) {

Expand Down

0 comments on commit bb89831

Please sign in to comment.