mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 20:43:30 +01:00
feat(guide): port remaining prs/issues from legacy (#10974)
* chore: remove await wait placeholder prefer using an explanatory placeholder rather than this artificial example original issue: https://github.com/discordjs/guide/issues/1360 * chore: remove implicit grant guide and add disclaimer issue: https://github.com/discordjs/guide/issues/1370/ pr: https://github.com/discordjs/guide/pull/1543/ * chore(sharding): improve broadcast sample and use of context argument original PR: https://github.com/discordjs/guide/pull/1624 * feat: add page about setup with proxy original PR: https://github.com/discordjs/guide/pull/1623 * chore: clarify hiding of commands original PR: https://github.com/discordjs/guide/pull/1617 * feat(voice): seeking original PR: https://github.com/discordjs/guide/pull/1483 * chore(oauth2): typo * chore: align with rest of the guide remove abstraction layers in ws proxy handling in favour of directly setting globals * chore: branding over grammar * Apply suggestions from code review Co-authored-by: Qjuh <76154676+Qjuh@users.noreply.github.com> * chore: remove now obsolete example explanation from comments --------- Co-authored-by: Qjuh <76154676+Qjuh@users.noreply.github.com>
This commit is contained in:
@@ -14,7 +14,7 @@ The slash command permissions for guilds are defaults only and can be altered by
|
||||
|
||||
## Member permissions
|
||||
|
||||
You can use `SlashCommandBuilder#setDefaultMemberPermissions` to set the default permissions required for a member to run the command. Setting it to `0` will prohibit anyone in a guild from using the command unless a specific overwrite is configured or the user has the Administrator permission flag.
|
||||
You can use `SlashCommandBuilder#setDefaultMemberPermissions` to set the default permissions required for a member to run the command. Setting it to `0` will hide the command from and prohibit anyone in a guild from using the command unless a specific overwrite is configured or the user has the Administrator permission flag.
|
||||
|
||||
For this, you'll introduce two common and simple moderation commands: `ban` and `kick`. For a ban command, a sensible default is to ensure that users already have the Discord permission `BanMembers` in order to use it.
|
||||
|
||||
|
||||
@@ -49,14 +49,12 @@ After you've sent an initial response, you may want to edit that response for va
|
||||
</Callout>
|
||||
|
||||
```js
|
||||
const wait = require('node:timers/promises').setTimeout;
|
||||
|
||||
client.on(Events.InteractionCreate, async (interaction) => {
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
|
||||
if (interaction.commandName === 'ping') {
|
||||
await interaction.reply('Pong!');
|
||||
await wait(2_000);
|
||||
// do something that requires time (database queries, api requests, ...)
|
||||
await interaction.editReply('Pong again!'); // [!code word:editReply]
|
||||
}
|
||||
});
|
||||
@@ -71,16 +69,13 @@ As previously mentioned, Discord requires an acknowledgement from your bot withi
|
||||
In this case, you can make use of the `ChatInputCommandInteraction#deferReply()` method, which triggers the `<application> is thinking...` message. This also acts as the initial response, to confirm to Discord that the interaction was received successfully and gives you a **15-minute timeframe to complete your tasks** before responding.
|
||||
|
||||
```js
|
||||
const wait = require('node:timers/promises').setTimeout;
|
||||
|
||||
client.on(Events.InteractionCreate, async (interaction) => {
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
|
||||
if (interaction.commandName === 'ping') {
|
||||
await interaction.deferReply(); // [!code word:deferReply]
|
||||
// you can take up to 15 minutes! We take 4 seconds to demonstrate this
|
||||
// since it is barely above the 3-second threshold for the initial response
|
||||
await wait(4_000);
|
||||
// you can do things that take time here (database queries, api requests, ...) that you need for the initial response
|
||||
// you can take up to 15 minutes, then the interaction token becomes invalid!
|
||||
await interaction.editReply('Pong!'); // [!code word:editReply]
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user