Winnmi
DIAdiscord.js - Imagine an app
•Created by Winnmi on 10/30/2024 in #djs-questions
using SlashCommandBuilder in Constructor
Hey im updating my old discord bot to v14 and used the slashcommand builder in a constructor after updaing it does not work anymore, can someone help me with that?
constructor() {
super(
new SlashCommandBuilder()
.setName("ban")
.setDescription("bans the given user")
.addUserOption((option) => option.setName("user").setDescription("user you want to ban").setRequired(true))
.addStringOption((option) => option.setName("reason").setDescription("reason for the ban")),
"mod",
["BAN_MEMBERS"],
false
);
}
constructor() {
super(
new SlashCommandBuilder()
.setName("ban")
.setDescription("bans the given user")
.addUserOption((option) => option.setName("user").setDescription("user you want to ban").setRequired(true))
.addStringOption((option) => option.setName("reason").setDescription("reason for the ban")),
"mod",
["BAN_MEMBERS"],
false
);
}
import { ButtonInteraction, CommandInteraction, Interaction, InteractionResponse, PermissionsString } from "discord.js";
import DiscordClient from "../../client/client";
import { SlashCommandBuilder, SlashCommandSubcommandsOnlyBuilder } from "@discordjs/builders";
export default abstract class BaseCommand {
constructor(private data: Omit<SlashCommandBuilder, "addSubcommand" | "addSubcommandGroup"> | SlashCommandSubcommandsOnlyBuilder, private category: string, private permissions: Array<PermissionsString>, private global: boolean) {}
getData(): Omit<SlashCommandBuilder, "addSubcommand" | "addSubcommandGroup"> | SlashCommandSubcommandsOnlyBuilder {
return this.data;
}
getName(): string {
return this.data.name;
}
getDescription(): string {
return this.data.description;
}
getCategory(): string {
return this.category;
}
getPermissions(): Array<PermissionsString> {
return this.permissions;
}
isGlobal(): boolean {
return this.global;
}
abstract run(client: DiscordClient, interaction: Interaction | ButtonInteraction | CommandInteraction): Promise<InteractionResponse<boolean> | void>;
}
import { ButtonInteraction, CommandInteraction, Interaction, InteractionResponse, PermissionsString } from "discord.js";
import DiscordClient from "../../client/client";
import { SlashCommandBuilder, SlashCommandSubcommandsOnlyBuilder } from "@discordjs/builders";
export default abstract class BaseCommand {
constructor(private data: Omit<SlashCommandBuilder, "addSubcommand" | "addSubcommandGroup"> | SlashCommandSubcommandsOnlyBuilder, private category: string, private permissions: Array<PermissionsString>, private global: boolean) {}
getData(): Omit<SlashCommandBuilder, "addSubcommand" | "addSubcommandGroup"> | SlashCommandSubcommandsOnlyBuilder {
return this.data;
}
getName(): string {
return this.data.name;
}
getDescription(): string {
return this.data.description;
}
getCategory(): string {
return this.category;
}
getPermissions(): Array<PermissionsString> {
return this.permissions;
}
isGlobal(): boolean {
return this.global;
}
abstract run(client: DiscordClient, interaction: Interaction | ButtonInteraction | CommandInteraction): Promise<InteractionResponse<boolean> | void>;
}
21 replies