diff --git a/astro.config.ts b/astro.config.ts index 6d13f8a..a3e4fca 100644 --- a/astro.config.ts +++ b/astro.config.ts @@ -19,13 +19,9 @@ export default defineConfig({ sidebar: [ { label: "Guides", - items: [ - // Each item here is one entry in the navigation menu. - { - label: "Example Guide", - link: "/guides/example/", - }, - ], + autogenerate: { + directory: "guides", + }, }, { label: "Classes", diff --git a/src/content/docs/guides/commands.mdx b/src/content/docs/guides/commands.mdx new file mode 100644 index 0000000..7b2bb13 --- /dev/null +++ b/src/content/docs/guides/commands.mdx @@ -0,0 +1,78 @@ +--- +title: Slash Commands +description: Registering and handling slash commands in DiscordLuau. +--- + +import { Steps } from '@astrojs/starlight/components'; +import { Aside } from '@astrojs/starlight/components'; + +[Slash commands](https://discord.com/developers/docs/interactions/application-commands) are Discord's officially supported +method of creating commands. They make interacting with your bot easier for users. Slash commands also allow for validation +of argument types, ephemeral responses, and so much more. + + + +1. Import the library and initialize the required modules: + + ```lua + local DiscordLuau = require("DiscordLuau") + + local DiscordSettings = DiscordLuau.SettingsBuilder.new("") + local DiscordClient = DiscordLuau.DiscordClient.new(DiscordSettings) + + -- Optionally enable verbose logging, to make it easier to debug + DiscordClient:setVerbose(true) + ``` + + + +2. Register a handler for the `onReady` signal: + + ```lua + DiscordClient.eventManager.onReady:connect(function() + print(`๐ŸŽ‰๐ŸŽ‰ {DiscordClient.discordUser.username} is online! ๐ŸŽ‰๐ŸŽ‰`) + end) + ``` + +3. Within the handler, we can now register our slash commands. + +4. First, we request Discord for access to slash commands. + + ```lua + local permissions = DiscordLuau.PermissionsBuilder.new() + permissions:addPermission( + DiscordLuau.PermissionsBuilder.Permissions.UseApplicationCommands + ) + ``` + +5. We can now register slash commands to our heart's content! + + ```lua + -- Create a slash command using `CommandBuilder` + local pingCommand = DiscordLuau.CommandBuilder + .new() + :setName("ping") + :setDescription("Pong?") + :setGuildPermissions(permissions) + :addContext(DiscordLuau.CommandBuilder.Context.Guild) + :setType(DiscordLuau.CommandBuilder.Type.ChatInput) + + -- Register our slash commands + DiscordClient.discordApplication + :setSlashCommandsAsync({ pingCommand }) + :after(function(data) + print("Registering slash commands...") + DiscordClient.discordApplication:fetchSlashCommandsAsync():after(function(...) + -- Optionally log information about our slash command + print(...) + end) + end) + ``` + + +That's all! For more details, refer to the relevant docs for [`DiscordApplication`](/classes/objects/discordapplication/) and +[`CommandBuilder`](/classes/builders/commandbuilder/). diff --git a/src/content/docs/guides/example.md b/src/content/docs/guides/example.md deleted file mode 100644 index ebd0f3b..0000000 --- a/src/content/docs/guides/example.md +++ /dev/null @@ -1,11 +0,0 @@ ---- -title: Example Guide -description: A guide in my new Starlight docs site. ---- - -Guides lead a user through a specific task they want to accomplish, often with a sequence of steps. -Writing a good guide requires thinking about what your users are trying to do. - -## Further reading - -- Read [about how-to guides](https://diataxis.fr/how-to-guides/) in the Diรกtaxis framework