Revert some changes of #8027 #8073
Replies: 7 comments 1 reply
-
All of these have been replaced as so: if (interaction.isModalSubmit) { ... }
if (interaction.type === InteractionType.ModalSubmit) { ... }
if (interaction.isCommand()) { ... }
if (interaction.type === InteractionType.ApplicationCommand) { ... }
if (interaction.isMessageComponent()) { ... }
if (interaction.type === InteractionType.MessageComponent) { ... } The interactions with types remains the same and they still narrow properly. Alternatively you can use The rationale was that because the type guards only aliased a single condition check, they were more of a shortcut method that a user can easily replicate, rather than an instance method of any actual value. |
Beta Was this translation helpful? Give feedback.
-
I understand that it's optional or even considered a shortcut @suneettipirneni, but we have plenty of shortcuts everywhere in Djs and in terms of DX, it's a good thing and keeps the code clean, having methods for some advanced checks and not having them for simple ones seems to me to be a change that doesn't add anything to Djs. Here is an example where it would not be aesthetic at all, if I only deal with slash-commands and modals, it is impossible to keep a uniform code: client.on('interactionCreate', (interaction) => {
if (interaction.type === InteractionType.ModalSubmit) {
// return this.functionToHandleModals(interaction);
}
if (interaction.isChatInputCommand()) {
// return this.functionToHandleSlashCommands(interaction);
}
}) |
Beta Was this translation helpful? Give feedback.
-
The other shortcuts were kept since they involved more than one check to the same interaction. As for djs having trivial shortcuts still in its library, it's a long term goal to remove them all. If your method's only job is to check the value of a single property on a class, that doesn't seem like it needs it's own method, unless it has type implications that can't be expressed with That's the equivalent of having a message.hasComponent(component);
message.components.includes(component); Sure the first is shorter and less code, but it's rather trivial so why does it need to be provided? In this specific case, it's also common practice to use duck-typing (.type === toSomeValue) and/or If your end goal is uniformity then shouldn't this suffice? client.on('interactionCreate', (interaction) => {
if (interaction instanceof ModalSubmitInteraction) {
// return this.functionToHandleModals(interaction);
}
if (interaction instanceof ChatInputCommandInteraction) {
// return this.functionToHandleSlashCommands(interaction);
}
}) |
Beta Was this translation helpful? Give feedback.
-
Okay, thanks for your complete answer @suneettipirneni, nevertheless I remain convinced that keeping this kind of methods can only be a bonus that has no negative points. I'd love to hear from other maintainers and developers about these changes, other perspectives would be welcome. Unfortunately, and this doesn't question all the work you do on the library, I find that, like a great majority of changes in this version 14, it only brings breaking-changes that are mostly useless and that will either kill projects because the migration will be so painful, or will make all the developers who give their all to their projects lose an incredible amount of time. |
Beta Was this translation helpful? Give feedback.
-
There can be a discussion but I'd rather it be in a GitHub discussion or another issue ticket. Since this current issue ticket is created as a bug report, but it's currently intended functionality. |
Beta Was this translation helpful? Give feedback.
-
Those typeguard's typings were wrong. If you write if (interaction.isModalSubmit()) {
if (interaction.isCommand()) {
console.log(interaction);
}
} It'll make the typing to if (interaction.type === InteractionType.ModalSubmit) {
if (interaction.type === InteractionType.ApplicationCommand) {
console.log(interaction);
}
} It'll become |
Beta Was this translation helpful? Give feedback.
-
This'll be coming via #8328. |
Beta Was this translation helpful? Give feedback.
-
Which package is this bug report for?
discord.js
Issue description
Some changes were done #8027 witch are not profitable for Djs :
<Interaction>.isModalSubmit()
has been removed, we can't filter anymore to redirect Modal submits interactions. (looks like a error)<Interaction>.isMessageComponent()
and<Interaction>.isCommand()
has been removed too, thoose two functions are practical and necessary because in most of the cases chat inputs and context menu commands are managed in a same class, the logic of the 3 types of commands are similar enough.Hi @suneettipirneni, is there a way that I wouldn't have seen who would justify these changes?
Package version
discord.js@14.0.0-dev.1654949087-96053ba
Priority this issue should have
High (immediate attention needed)
I have tested this issue on a development release
96053ba
Beta Was this translation helpful? Give feedback.
All reactions