Skip to content

Commit

Permalink
fix: mention loadMessageCommandListeners in the guide
Browse files Browse the repository at this point in the history
Closes #235
  • Loading branch information
favna committed Apr 13, 2023
1 parent b5b5c48 commit 37322df
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
37 changes: 35 additions & 2 deletions docs/Guide/getting-started/creating-a-basic-command.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,36 @@ Let's go over what is defined in the constructor in this code:
- `aliases`: other ways users can call the command. You can have as many as you want!
- `description`: some text that you can use to display when a "help" command is used.

There are many other properties available, all of which can be seen in the [`CommandOptions`] interface, but will also
be explained in upcoming sections.
There are many other properties available, all of which can be seen in the [`CommandOptions`][commandoptions] interface,
but will also be explained in upcoming sections.

## Creating the `messageRun` method

:::danger

If you want to use message commands in your Sapphire bot, you have to make sure you meet the following prerequisites:

1. Enable the `Message Content Intent` under `Privileged Gateway Intents` on the [Discord Developer Portal][dev-portal]
for your application.
2. In your Sapphire client options, set the [`intents`] property to include the intents
[`GatewayIntentBits.GuildMessages`][guild_messages_intent], [`GatewayIntentBits.Guilds`][guilds_intent], and
[`GatewayIntentBits.MessageContent`][message_content_intent].
3. In your Sapphire client options set [`loadMessageCommandListeners`][loadMessageCommandListeners] to `true`.

All in all your code should look something like this:

```typescript ts2esm2cjs|{4-12}|{4-12}
import { SapphireClient } from '@sapphire/framework';
import { GatewayIntentBits } from 'discord.js';

const client = new SapphireClient({
intents: [GatewayIntentBits.MessageContent, GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages],
loadMessageCommandListeners: true
});
```

:::

Commands have a `messageRun` method, which executes the command logic when it is invoked from a message. Define this
below the command's constructor:

Expand Down Expand Up @@ -150,3 +175,11 @@ For handling subcommands, please refer to the [Sapphire Plugin Subcommands][saph
[load-message-commands-option]:
../../Documentation/api-framework/interfaces/SapphireClientOptions#loadmessagecommandlisteners
[saph-plug-subcom]: ../plugins/Subcommands/getting-started
[guild_messages_intent]: https://discord-api-types.dev/api/discord-api-types-v10/enum/GatewayIntentBits#GuildMessages
[guilds_intent]: https://discord-api-types.dev/api/discord-api-types-v10/enum/GatewayIntentBits#Guilds
[message_content_intent]: https://discord-api-types.dev/api/discord-api-types-v10/enum/GatewayIntentBits#MessageContent
[`intents`]:
https://old.discordjs.dev/#/docs/discord.js/main/typedef/ClientOptions:~:text=use%20upon%20login-,intents,-IntentsResolvable
[dev-portal]: https://discord.com/developers
[loadMessageCommandListeners]:
../../Documentation/api-framework/interfaces/SapphireClientOptions#loadmessagecommandlisteners
33 changes: 33 additions & 0 deletions docs/Guide/getting-started/getting-started-with-sapphire.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,31 @@ Here is an example of a package.json file:

:::

:::danger

If you want to use message commands in your Sapphire bot, you have to make sure you meet the following prerequisites:

1. Enable the `Message Content Intent` under `Privileged Gateway Intents` on the [Discord Developer Portal][dev-portal]
for your application.
2. In your Sapphire client options, set the [`intents`] property to include the intents
[`GatewayIntentBits.GuildMessages`][guild_messages_intent], [`GatewayIntentBits.Guilds`][guilds_intent], and
[`GatewayIntentBits.MessageContent`][message_content_intent].
3. In your Sapphire client options set [`loadMessageCommandListeners`][loadMessageCommandListeners] to `true`.

All in all your code should look something like this:

```typescript ts2esm2cjs|{4-12}|{4-12}
import { SapphireClient } from '@sapphire/framework';
import { GatewayIntentBits } from 'discord.js';

const client = new SapphireClient({
intents: [GatewayIntentBits.MessageContent, GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages],
loadMessageCommandListeners: true
});
```

:::

## Creating an `index.js` file

While it doesn't have to be called `index.js`, this file will be the main file for your bot (otherwise known as the
Expand Down Expand Up @@ -91,3 +116,11 @@ And that's it for your `index.js` file! In the end, your directory should look l
[djs-client]: https://old.discordjs.dev/#/docs/discord.js/main/class/Client
[baseuserdirectory]: ../../Documentation/api-framework/interfaces/SapphireClientOptions#baseuserdirectory
[securing-your-token]: https://discordjs.guide/preparations/setting-up-a-bot-application.html#your-token
[guild_messages_intent]: https://discord-api-types.dev/api/discord-api-types-v10/enum/GatewayIntentBits#GuildMessages
[guilds_intent]: https://discord-api-types.dev/api/discord-api-types-v10/enum/GatewayIntentBits#Guilds
[message_content_intent]: https://discord-api-types.dev/api/discord-api-types-v10/enum/GatewayIntentBits#MessageContent
[`intents`]:
https://old.discordjs.dev/#/docs/discord.js/main/typedef/ClientOptions:~:text=use%20upon%20login-,intents,-IntentsResolvable
[dev-portal]: https://discord.com/developers
[loadMessageCommandListeners]:
../../Documentation/api-framework/interfaces/SapphireClientOptions#loadmessagecommandlisteners

1 comment on commit 37322df

@vercel
Copy link

@vercel vercel bot commented on 37322df Apr 13, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.