-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
toJSON() function in ChatInputApplicationCommandData type #9299
Comments
Can you provide a code sample of where you encountered this issue? |
ye client.commands.forEach((command: BaseCommand, name: String) => {
commands.push(command.getData().toJSON()); //encounterd it on this line
}); BaseCommand import { Interaction, ChatInputApplicationCommandData, CommandInteractionOption } from 'discord.js';
import DiscordClient from '../../client/client';
export default abstract class BaseCommand {
constructor(private data: ChatInputApplicationCommandData, private category: string) {}
getName(): String { return this.data.name; }
getDescription(): String { return this.data.description; }
getOptions(): Array<CommandInteractionOption> | undefined { return this.data.options;}
getData(): ChatInputApplicationCommandData { return this.data; }
getCategory(): string { return this.category; }
abstract run(client: DiscordClient, interaction: Interaction): Promise<void>;
} DiscordClient import { Client, ClientOptions, Collection } from 'discord.js';
import BaseEvent from '../utils/structures/BaseEvent';
import BaseCommand from '../utils/structures/BaseCommand';
export default class DiscordClient extends Client {
private _commands = new Collection<string, BaseCommand>();
private _events = new Collection<string, BaseEvent>();
private _prefix: string = '!';
constructor(options: ClientOptions) {
super(options);
}
get commands(): Collection<string, BaseCommand> { return this._commands; }
get events(): Collection<string, BaseEvent> { return this._events; }
get prefix(): string { return this._prefix; }
set prefix(prefix: string) { this._prefix = prefix; }
} edit: the problem says |
Was half-expecting a minimal code sample, alas, what is an example of a command? |
ye import { ChatInputCommandInteraction, Interaction, SlashCommandBuilder } from 'discord.js';
import BaseCommand from '../../utils/structures/BaseCommand';
import DiscordClient from '../../client/client';
export default class TestCommand extends BaseCommand {
constructor() {
super(new SlashCommandBuilder()
.setName("test"),
'testing'
);
}
async run(client: DiscordClient, interaction: ChatInputCommandInteraction) {
await interaction.reply("hi")
}
} |
You are passing a builder in the first parameter of the constructor, but you have typed it as something else. You should get a type error; in no way are these types compatible. |
Which package is this feature request for?
discord.js
Feature
the
toJSON()
function dosnt seem to be in theChatInputApplicationCommandData
type but in the guide it seems that it does exist and i know it does exist. so it might be good to add itIdeal solution or implementation
Add the
toJSON()
function to theChatInputApplicationCommandData
typeAlternative solutions or implementations
No response
Other context
its just anoying to see all these typescript problems and this will also fix intelisense by adding the function to it
The text was updated successfully, but these errors were encountered: