discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.32k stars 3.97k forks source link

Add .sourceType to the ModalSubmitInteraction object #8670

Closed OakLoaf closed 1 year ago

OakLoaf commented 2 years ago

Which package is the feature request for?

discord.js

Feature

Add .sourceType or similarly named, which holds the type of interaction that created the form, eg. Button, ContextMenu, SlashCommand,

Ideal solution or implementation

ModalSubmitInteraction#sourceType will return the type of the interaction that triggered the modal.

Alternative solutions or implementations

No response

Other context

I am unsure whether this is something that is easily implementable within the restrictions of the DiscordAPI but if it is it would be very useful.

imranbarbhuiya commented 2 years ago

You can use https://discord.js.org/#/docs/discord.js/main/class/ModalSubmitInteraction?scrollTo=isFromMessage

OakLoaf commented 2 years ago

You can use https://discord.js.org/#/docs/discord.js/main/class/ModalSubmitInteraction?scrollTo=isFromMessage

This does not solve the issue; this only works for separating the types in to 2 categories.

kyranet commented 2 years ago

The problem with what you're suggesting, is that it's impossible to safely narrow the interaction's type, so there isn't really much of a benefit here, not for TypeScript users at least.

Alternatively, you can use custom_id and assume the source if it matches something, e.g. if a modal with a custom id of role-confirm:222197033908436994 is sent exclusively from message components, you can safely assume that a modal which custom id starts with role-confirm: will always come from a message.

OakLoaf commented 2 years ago

The problem with what you're suggesting, is that it's impossible to safely narrow the interaction's type, so there isn't really much of a benefit here, not for TypeScript users at least.

I don't quite understand what you mean by this?

JPBM135 commented 2 years ago

I don't quite understand what you mean by this?

Discord does not natively send the interaction type that submitted the modal, so there is now way of actually doing that, what Kyra suggested is that you can add some type of marker in the custom id that allows you to know where the modal came from

Jiralite commented 1 year ago

Additionally, this could be submitted as a feature request to Discord.