-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
feat(templates): add interaction handler templates #166
feat(templates): add interaction handler templates #166
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add newlines to the end of the files.
the indents on these templates are pretty messy, some of the editReply keywords are missing the await keyword and spacing should be added around the objects. eg. - interaction.editReply({content: "Hello World"})
+ await interaction.editReply({ content: "Hello World" }) Note: this is just my opinion |
"category": "interaction-handlers", | ||
} | ||
--- | ||
const { InteractionHandler, InteractionHandlerTypes } = require('@sapphire/framework'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For all template files use the Sapphire prettier config to format them. Copy the template code to the prettier playground then paste the result back.
Also for all JS template files please add JSDoc comments similar to the already existing ones to add some basic types to JS code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So adding
/**
* @param {InteractionHandler.Context} context
*/
to every JS interaction-handler template
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
public override async run(interaction: AutocompleteInteraction) { | ||
// Do Whatever | ||
await interaction.editReply({ content: 'Hello World' }); | ||
} | ||
|
||
public override async parse(interaction: AutocompleteInteraction) { | ||
// Make sure the interaction you want is what you get | ||
if (!interaction.customId.startsWith('{{name}}')) return this.none(); | ||
await interaction.deferReply(); | ||
return this.some(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should do the same as the JS template!
@ApplyOptions<InteractionHandler.Options>({ | ||
type: InteractionHandlerTypes.Autocomplete | ||
}) | ||
export default class extends InteractionHandler { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't do export defaults in other templates
const { InteractionHandler, InteractionHandlerTypes } = require('@sapphire/framework'); | ||
class ButtonHandler extends InteractionHandler { | ||
/** | ||
* @param {InteractionHandler.Context} context | ||
*/ | ||
constructor(ctx, options) { | ||
super(ctx, { | ||
...options, | ||
interactionHandlerType: InteractionHandlerTypes.Button | ||
}); | ||
} | ||
|
||
parse(interaction) { | ||
if (interaction.customId !== 'my-awesome-button') return this.none(); | ||
return this.some(); | ||
} | ||
|
||
async run(interaction) { | ||
await interaction.reply({ | ||
content: 'Hello from a button interaction handler!', | ||
// Let's make it so only the person who pressed the button can see this message! | ||
ephemeral: true | ||
}); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting is not done
}); | ||
} | ||
|
||
parse(interaction) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try to be consistent with the parse vs run location in the files!
class ModalHandler extends InteractionHandler { | ||
/** | ||
* @param {InteractionHandler.Context} context | ||
*/ | ||
constructor(ctx, options) { | ||
super(ctx, { | ||
...options, | ||
interactionHandlerType: InteractionHandlerTypes.ModalSubmit | ||
}); | ||
} | ||
|
||
parse(interaction) { | ||
if (interaction.customId !== 'hello-popup') return this.none(); | ||
return this.some(); | ||
} | ||
|
||
async run(interaction) { | ||
await interaction.reply({ | ||
content: 'Thank you for submitting the form!', | ||
ephemeral: true | ||
}); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
class MenuHandler extends InteractionHandler { | ||
/** | ||
* @param {InteractionHandler.Context} context | ||
*/ | ||
constructor(ctx, options) { | ||
super(ctx, { | ||
...options, | ||
interactionHandlerType: InteractionHandlerTypes.SelectMenu | ||
}); | ||
} | ||
|
||
parse(interaction) { | ||
if (interaction.customId !== 'my-echo-select') return this.none(); | ||
return this.some(); | ||
} | ||
|
||
async run(interaction) { | ||
await interaction.reply({ | ||
// Remember how we can have multiple values? Let's get the first one! | ||
content: `You selected: ${interaction.values[0]}` | ||
}); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
To be closed has been moved to #216 |
Title says it all,
all TS ones are tested and the JS ones are from the guide