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

interactions #5106

Closed
wants to merge 1 commit into from
Closed

interactions #5106

wants to merge 1 commit into from

Conversation

devsnek
Copy link
Member

@devsnek devsnek commented Dec 11, 2020

Please describe the changes this PR makes and why it should be merged:

Status

This will need #4879 before it lands.

  • Code changes have been tested against the Discord API, or there are no code changes
  • I know how to update typings and have done so, or typings don't need updating

Semantic versioning classification:

  • This PR changes the library's interface (methods or parameters added)
    • This PR includes breaking changes (methods removed or renamed, parameters moved or removed)
  • This PR only includes non-code changes, like changes to documentation, README, etc.

@SpaceEEC SpaceEEC linked an issue Dec 11, 2020 that may be closed by this pull request
@devsnek devsnek changed the title interactions wip interactions Dec 11, 2020
src/client/Client.js Outdated Show resolved Hide resolved
src/client/InteractionClient.js Outdated Show resolved Hide resolved
src/client/InteractionClient.js Show resolved Hide resolved
src/client/InteractionClient.js Outdated Show resolved Hide resolved
src/client/InteractionClient.js Outdated Show resolved Hide resolved
src/structures/ApplicationCommand.js Outdated Show resolved Hide resolved
src/structures/ApplicationCommand.js Show resolved Hide resolved
src/structures/Interaction.js Show resolved Hide resolved
src/structures/Interaction.js Outdated Show resolved Hide resolved
src/structures/Interaction.js Outdated Show resolved Hide resolved
src/client/InteractionClient.js Outdated Show resolved Hide resolved
src/structures/ApplicationCommand.js Outdated Show resolved Hide resolved
src/structures/Guild.js Outdated Show resolved Hide resolved
src/structures/ApplicationCommand.js Outdated Show resolved Hide resolved
src/client/InteractionClient.js Outdated Show resolved Hide resolved
src/structures/Interaction.js Outdated Show resolved Hide resolved
src/structures/Interaction.js Outdated Show resolved Hide resolved
@ThaTiemsz
Copy link
Contributor

I feel like this is missing a couple of stuff. Such as editing commands, editing the message(s), and sending follow up messages.

Side note: I was thinking, perhaps Interaction.options could be mapped to a Collection so you can easily do Interaction.options.get("key") instead of having to do Interaction.options.find(o => o.name === "key") every time.

@devsnek
Copy link
Member Author

devsnek commented Dec 13, 2020

options may support repetition in the future, so a map would cause issues. note that this is only intended to accurately expose the capability of the api, for higher level interaction you should use something like commando.

@ckohen
Copy link
Member

ckohen commented Dec 15, 2020

This will likely need a InteractionMessageOptions as Interactions don't take all the same options as normal messages (including the additional ephemeral flag)

src/client/InteractionClient.js Outdated Show resolved Hide resolved
src/client/InteractionClient.js Outdated Show resolved Hide resolved

/**
* Emitted when an interaction is created.
* @event Client#interactionCreate
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there should also be a docstring to indicate this event is emitted on InteractionClient

or perhaps just emit the event on the InteractionClient only

src/client/InteractionClient.js Show resolved Hide resolved
src/client/InteractionClient.js Show resolved Hide resolved
src/client/voice/dispatcher/StreamDispatcher.js Outdated Show resolved Hide resolved
@almostSouji
Copy link
Member

almostSouji commented Dec 15, 2020

note: documentation has been finalized (at least for the beta period) at https://discord.com/developers/docs/interactions/slash-commands

src/client/InteractionClient.js Outdated Show resolved Hide resolved
src/structures/APIMessage.js Outdated Show resolved Hide resolved
src/client/InteractionClient.js Show resolved Hide resolved
Copy link

@Romvnly-Gaming Romvnly-Gaming left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.client.api.applications('@me') should be this.client.api.applications(this.client.id) Discord expects a snowflake.

Copy link

@XynoxTheDev XynoxTheDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sry by mistake, pls delete this.

@ckohen
Copy link
Member

ckohen commented Dec 17, 2020

This will need changes to APIRouter to account for all additional type of major id: webhooks

@devsnek devsnek force-pushed the interactions branch 2 times, most recently from 637531b to 1de89f0 Compare December 18, 2020 02:45
@ckohen
Copy link
Member

ckohen commented Mar 15, 2021

So we would make two calls to .reply() then? One as .reply({ deferred: true, ephemeral: true }) and the second would be the actual response? And I can't seem to find where this is implemented.

@devsnek
Copy link
Member Author

devsnek commented Mar 15, 2021

you just call reply normally. the library automatically handles whether it should be deferred or not, and the message utils handle the ephemeral option.

src/structures/CommandInteraction.js Show resolved Hide resolved
src/client/InteractionClient.js Show resolved Hide resolved
Comment on lines 978 to 987
public readonly applicationID: Snowflake;
public readonly channel: TextChannel | NewsChannel | DMChannel | null;
public readonly channelID: Snowflake | null;
public readonly guild: Guild | null;
public readonly guildID: Snowflake | null;
public readonly id: Snowflake;
public readonly member: GuildMember | null;
public readonly token: string;
public readonly type: InteractionType;
public readonly user: User | null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public readonly applicationID: Snowflake;
public readonly channel: TextChannel | NewsChannel | DMChannel | null;
public readonly channelID: Snowflake | null;
public readonly guild: Guild | null;
public readonly guildID: Snowflake | null;
public readonly id: Snowflake;
public readonly member: GuildMember | null;
public readonly token: string;
public readonly type: InteractionType;
public readonly user: User | null;
public applicationID: Snowflake;
public channel: TextChannel | NewsChannel | DMChannel | null;
public channelID: Snowflake | null;
public guild: Guild | null;
public guildID: Snowflake | null;
public id: Snowflake;
public member: GuildMember | null;
public token: string;
public type: InteractionType;
public user: User | null;

Comment on lines 341 to 345
public readonly commandID: Snowflake;
public readonly commandName: string;
public readonly createdAt: Date;
public readonly createdTimestamp: number;
public readonly options: object;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public readonly commandID: Snowflake;
public readonly commandName: string;
public readonly createdAt: Date;
public readonly createdTimestamp: number;
public readonly options: object;
public commandID: Snowflake;
public commandName: string;
public readonly createdAt: Date;
public readonly createdTimestamp: number;
public options: object;

@ckohen
Copy link
Member

ckohen commented Mar 15, 2021

you just call reply normally. the library automatically handles whether it should be deferred or not, and the message utils handle the ephemeral option.

I see the automatic handling of deferred and how ephemeral is handled, I see no way to defer with ephemeral, as it must be set in the original callback.

Side note: the deferred message will show the user the interaction has timed out with the current handling, even after a reply, if the timeout for deferred has been reached.

@ChristianTucker
Copy link

Pulled the PR to mess about, may want to modify the readme to show the new parameter requirements for Client (CLIENT_MISSING_INTENTS). The documentation is also lacking, but I'm assuming that it will be automatically generated on merge.

@JKLorenzo
Copy link
Contributor

Pulled the PR to mess about, may want to modify the readme to show the new parameter requirements for Client (CLIENT_MISSING_INTENTS). The documentation is also lacking, but I'm assuming that it will be automatically generated on merge.

I think its because of #4879.

@vaporoxx
Copy link
Contributor

#5323 Takes care of the README change.

src/structures/CommandInteraction.js Show resolved Hide resolved
Comment on lines +130 to +149
* @param {(StringResolvable | APIMessage)?} content The content for the message.
* @param {(MessageOptions | MessageAdditions)?} options The options to provide.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param {(StringResolvable | APIMessage)?} content The content for the message.
* @param {(MessageOptions | MessageAdditions)?} options The options to provide.
* @param {StringResolvable|APIMessage} content The content for the message.
* @param {MessageOptions|MessageAdditions} [options] The options to provide.

* @type {Object}
* @readonly
*/
this.options = data.data.options.map(map);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.options = data.data.options.map(map);
this.options = data.data.options?.map(map);

options can be undefined when a command doesn't have parameters (or none are given when executing the command)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.options = data.data.options.map(map);
this.options = data.data.options?.map(map) ?? [];

Wouldn't it be better if options was an empty array, instead of just being undefined?

Copy link
Contributor

@vaporoxx vaporoxx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

client.interactionClient.createCommand() is broken atm, this should fix it

@@ -12,6 +12,8 @@ module.exports = (client, { d: data }, shard) => {
client.users.cache.set(clientUser.id, clientUser);
}

client.applicationID = data.application.id;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
client.applicationID = data.application.id;
client.applicationID = data.application.id;
client.interactionClient.applicationID = data.application.id;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
client.applicationID = data.application.id;
client.applicationID = client.interactionClient.applicationID = data.application.id;

* @returns {ApplicationCommand} The created command.
*/
async createCommand(command, guildID) {
let path = this.client.api.applications(this.clientID);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let path = this.client.api.applications(this.clientID);
let path = this.client.api.applications(this.applicationID);


/**
* Edit this command.
* @param {ApplicationCommandOptions} data The data to update the command with
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this should be a separate type since all of the endpoint parameters are optional yet the type requires them + others that are thrown away

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alternatively use Partial<ApplicationCommandOptions> as was going to be documented by #5144 but document it here instead

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

devsnek#13 creates a new typedef for that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the typedef created there still does not respect edit data being optional, while options becomes optional, name and description still are not.

@ckohen
Copy link
Member

ckohen commented Mar 25, 2021

Seems this commit reverted all the typings and jsdoc changes c3c00fc

Also this seems like it needs #5223 to land now so editing and deleting original is possible (for deferred responses especially)

@ObscuritySRL
Copy link
Contributor

ObscuritySRL commented Mar 28, 2021

CommandInteraction.js:42:32 should be ?. as o.options can be null for SUB_COMMAND, causing an error at .map(map).

* @type {?GuildMember}
* @readonly
*/
this.member = data.member ? this.guild?.members.add(data.member, false) : null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.member = data.member ? this.guild?.members.add(data.member, false) : null;
this.member = (data.member && this.guild) ? this.guild.members.add(data.member, false) : null;

*/
class InteractionClient extends BaseClient {
/**
* @param {Options} options Options for the client.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this Options type doesn't exist, would probably be good to give it a better name too

@code913

This comment has been minimized.

@almostSouji
Copy link
Member

superseded by #5448

@almostSouji almostSouji closed this Apr 4, 2021
@devsnek devsnek deleted the interactions branch April 12, 2021 22:08
@thepwrtank18
Copy link

#5448 is done!

@iCrawl iCrawl added this to the Version 13 milestone Jun 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Slash Commands Support