Skip to content
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

Closed
phant0m2290 opened this issue Mar 30, 2023 · 5 comments
Closed

toJSON() function in ChatInputApplicationCommandData type #9299

phant0m2290 opened this issue Mar 30, 2023 · 5 comments

Comments

@phant0m2290
Copy link

Which package is this feature request for?

discord.js

Feature

the toJSON() function dosnt seem to be in the ChatInputApplicationCommandData type but in the guide it seems that it does exist and i know it does exist. so it might be good to add it

Ideal solution or implementation

Add the toJSON() function to the ChatInputApplicationCommandData type

Alternative 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

@Jiralite
Copy link
Member

Jiralite commented Mar 30, 2023

Can you provide a code sample of where you encountered this issue?

@phant0m2290
Copy link
Author

phant0m2290 commented Mar 30, 2023

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 Property 'toJSON' does not exist on type 'ChatInputApplicationCommandData'

@Jiralite
Copy link
Member

Was half-expecting a minimal code sample, alas, what is an example of a command?

@phant0m2290
Copy link
Author

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")
  }
}

@Jiralite
Copy link
Member

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.

@Jiralite Jiralite closed this as not planned Won't fix, can't repro, duplicate, stale Mar 30, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants