Skip to content

Commit

Permalink
feature: implement guides for Discord-Luau
Browse files Browse the repository at this point in the history
  • Loading branch information
4x8Matrix committed May 30, 2024
1 parent c696b7b commit 0082d64
Show file tree
Hide file tree
Showing 5 changed files with 349 additions and 2 deletions.
8 changes: 7 additions & 1 deletion astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@ export default defineConfig({
},
integrations: [
starlight({
title: "DiscordLuau Docs",
title: "Discord-Luau",
favicon: "public/favicon.png",
social: {
github: "https://github.com/DiscordLuau/discord-luau",
},
sidebar: [
{
label: "Getting Started",
autogenerate: {
directory: "getting-started",
},
},
{
label: "Guides",
autogenerate: {
Expand Down
2 changes: 1 addition & 1 deletion discord-luau
Submodule discord-luau updated 98 files
+0 βˆ’20 .github/workflows/pull-request-moonwave.yml
+0 βˆ’20 .github/workflows/pull-request-selene.yml
+0 βˆ’20 .github/workflows/pull-request-stylua.yml
+4 βˆ’4 .github/workflows/update-documentation.yml
+1 βˆ’8 .vscode/settings.json
+18 βˆ’23 Examples/Commands.luau
+31 βˆ’34 Examples/Components.luau
+7 βˆ’4 Examples/Development.luau
+0 βˆ’20 Examples/Files.luau
+6 βˆ’3 Examples/Message.luau
+34 βˆ’40 Examples/Modal.luau
+6 βˆ’6 Examples/Precence.luau
+0 βˆ’131 Package/Classes/Builders/ActivityBuilder.luau
+283 βˆ’0 Package/Classes/Builders/ApplicationCommandBuilder.luau
+367 βˆ’0 Package/Classes/Builders/ApplicationCommandOptionBuilder.luau
+0 βˆ’316 Package/Classes/Builders/AutomoderationRuleBuilder.luau
+0 βˆ’292 Package/Classes/Builders/CommandBuilder.luau
+0 βˆ’373 Package/Classes/Builders/CommandOptionBuilder.luau
+128 βˆ’0 Package/Classes/Builders/DiscordActivityBuilder.luau
+306 βˆ’0 Package/Classes/Builders/DiscordAutomoderationRuleBuilder.luau
+373 βˆ’0 Package/Classes/Builders/DiscordEmbedBuilder.luau
+27 βˆ’27 Package/Classes/Builders/DiscordIntentsBuilder.luau
+191 βˆ’0 Package/Classes/Builders/DiscordMessageBuilder.luau
+95 βˆ’0 Package/Classes/Builders/DiscordModalBuilder.luau
+48 βˆ’48 Package/Classes/Builders/DiscordPermissionsBuilder.luau
+148 βˆ’0 Package/Classes/Builders/DiscordPresenceBuilder.luau
+74 βˆ’0 Package/Classes/Builders/DiscordSettingsBuilder.luau
+0 βˆ’438 Package/Classes/Builders/EmbedBuilder.luau
+0 βˆ’316 Package/Classes/Builders/MessageBuilder.luau
+0 βˆ’108 Package/Classes/Builders/ModalBuilder.luau
+0 βˆ’151 Package/Classes/Builders/PresenceBuilder.luau
+0 βˆ’74 Package/Classes/Builders/SettingsBuilder.luau
+27 βˆ’36 Package/Classes/DiscordClient.luau
+20 βˆ’20 Package/Classes/Interface/ActionRowBuilder.luau
+27 βˆ’30 Package/Classes/Interface/ButtonBuilder.luau
+48 βˆ’49 Package/Classes/Interface/SelectionBuilder.luau
+30 βˆ’33 Package/Classes/Interface/TextInputBuilder.luau
+29 βˆ’95 Package/Classes/Network/DiscordGateway.luau
+115 βˆ’140 Package/Classes/Network/DiscordShard.luau
+8 βˆ’7 Package/Classes/Network/DiscordUDP.luau
+79 βˆ’84 Package/Classes/Network/DiscordVoiceConnection.luau
+12 βˆ’17 Package/Classes/Network/DiscordWebsocket.luau
+4 βˆ’4 Package/Classes/Network/HTTPRatelimit.luau
+2 βˆ’2 Package/Classes/Network/HTTPScheduler.luau
+6 βˆ’6 Package/Classes/Network/Middleware/EventIn.luau
+6 βˆ’6 Package/Classes/Network/Middleware/EventOut.luau
+0 βˆ’90 Package/Classes/Network/Resolvable.luau
+4 βˆ’4 Package/Classes/Network/WebsocketBuffer.luau
+39 βˆ’50 Package/Classes/Objects/DiscordApplication.luau
+13 βˆ’19 Package/Classes/Objects/DiscordAutomoderationRule.luau
+3 βˆ’3 Package/Classes/Objects/DiscordCache.luau
+33 βˆ’67 Package/Classes/Objects/DiscordChannel.luau
+12 βˆ’15 Package/Classes/Objects/DiscordEmoji.luau
+80 βˆ’137 Package/Classes/Objects/DiscordGuild.luau
+32 βˆ’58 Package/Classes/Objects/DiscordGuildMember.luau
+12 βˆ’15 Package/Classes/Objects/DiscordGuildRole.luau
+42 βˆ’65 Package/Classes/Objects/DiscordInteraction.luau
+5 βˆ’10 Package/Classes/Objects/DiscordInvite.luau
+57 βˆ’115 Package/Classes/Objects/DiscordMessage.luau
+19 βˆ’32 Package/Classes/Objects/DiscordTextChannel.luau
+15 βˆ’48 Package/Classes/Objects/DiscordThreadChannel.luau
+13 βˆ’16 Package/Classes/Objects/DiscordUser.luau
+23 βˆ’31 Package/Classes/Objects/DiscordVoiceChannel.luau
+2 βˆ’2 Package/Classes/Objects/EndpointCache.luau
+13 βˆ’11 Package/Classes/Objects/EventManager.luau
+2 βˆ’1 Package/Data/DiscordEndpoints.luau
+3 βˆ’4 Package/Enums/CacheType.luau
+3 βˆ’4 Package/Enums/DiscordEvents.luau
+1 βˆ’2 Package/Enums/Intents.luau
+0 βˆ’10 Package/Enums/ResolveableType.luau
+2 βˆ’2 Package/Enums/VoiceWebsocketOperationCodes.luau
+1 βˆ’1 Package/Enums/WebsocketCloseCodes.luau
+1 βˆ’2 Package/Enums/WebsocketEvents.luau
+1 βˆ’1 Package/Enums/WebsocketOperationCodes.luau
+5 βˆ’2 Package/Enums/WebsocketOperationKeys.luau
+3 βˆ’3 Package/Std/Datetime.luau
+4 βˆ’6 Package/Std/Net.luau
+3 βˆ’3 Package/Std/Process.luau
+3 βˆ’3 Package/Std/Serde.luau
+3 βˆ’3 Package/Std/Task.luau
+11 βˆ’0 Package/Types/DiscordComponent.luau
+23 βˆ’0 Package/Types/DiscordGuild.luau
+5 βˆ’0 Package/Types/DiscordInteraction.luau
+6 βˆ’0 Package/Types/DiscordMessage.luau
+16 βˆ’44 Package/Utils/Construct.luau
+1 βˆ’1 Package/Utils/Dictionary/FetchKeys.luau
+1 βˆ’5 Package/Utils/Dictionary/IsUnique.luau
+3 βˆ’3 Package/Utils/Enumerate.luau
+16 βˆ’44 Package/Utils/Inherit.luau
+1 βˆ’5 Package/Vendor/Embedded/4x8Matrix/Console.luau
+1 βˆ’2 Package/Vendor/Embedded/Redblox/Future.luau
+1 βˆ’1 Package/Vendor/Embedded/Redblox/Spawn.luau
+8 βˆ’11 Package/Vendor/Embedded/Sleitnick/Signal.luau
+1 βˆ’1 Package/Vendor/Signal.luau
+42 βˆ’108 Package/init.luau
+1 βˆ’4 aftman.toml
+12 βˆ’12 init.luau
+1 βˆ’2 selene.toml
177 changes: 177 additions & 0 deletions src/content/docs/getting-started/environment.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
---
title: Environment Setup
description: Instructions for noobs on how to set up a healthy environment for a Discord Application
---

This guide will provide a brief overview on how to setup both the [Lune](https://lune-org.github.io/docs) runtime
as well as several tools that will help you in the production of a DiscordLuau application.

This guide assumes you're a classic Roblox developer that's never looked at software development outside of the Roblox Engine

## Required

The following tools are required to have a healthy environment to build a DiscordLuau application

### Visual Studio Code

Visual Studio Code is a common IDE that DiscordLuau will assume you'll be using, there will be several references to VSCode, or branches alike
VSCode in this guide.

To install Visual Studio Code, please head to their official website, and download the binaries required for your platform;

- https://code.visualstudio.com/

*(From this point on, we expect that you've created a new file system Folder for your discord application,
and have opened that folder in VSCode)*

### Aftman

[Aftman](https://github.com/LPGhatguy/aftman) is a [toolchain manager](https://en.wikipedia.org/wiki/Toolchain), enabling
developers to easily download and setup project tooling.

This guide assumes you're going to be using aftman, however, if not - there will be links to documentation to indicate other
installation methods.

#### Installation of Aftman

Please follow the [following guide on how to install the Aftman toolmanager](https://github.com/LPGhatguy/aftman?tab=readme-ov-file#installation)

---

### Lune

Lune in a [Luau](https://luau-lang.org/) [runtime](https://en.wikipedia.org/wiki/Runtime_system), enabling us to take advantage
of Luau, beyond the Roblox engine, there are some destinct differences from Lune and the compiled Luau binaries though,
the major factor being that Lune provides a standard library.

To learn more about lune, please [head over here](https://lune-org.github.io/docs)

#### Installation of Lune

Installing lune can be done so through Aftman as such:

```bash
aftman add lune-org/lune
```

To verify that Lune has installed correctly, you can execute the following command in a Command Line / Terminal to interact
with the lune CLI:

```bash
lune
```

:::note
If you get an error upon the above Lune command, please ensure that the envrionment variables are setup as per aftman requires - otherwise
your computer won't know where to find Lune!
:::

#### Setup of Lune

Lune installation is not enough for us to fully take advantage of this runtime in our IDE, we also need to setup some of the
additional rules that Lune requires;

Please follow the guide [linked here](https://lune-org.github.io/docs/getting-started/4-editor-setup)

---

### Luau-Lsp

[Luau LSP](https://github.com/JohnnyMorganz/luau-lsp) is a Language server for the Luau programming language, this is going to help make your life easier when both using luau, and
interacting with DiscordLuau's type interface.

#### Installation of Luau-Lsp

- [VSCode IDE](https://marketplace.visualstudio.com/items?itemName=JohnnyMorganz.luau-lsp)
- [VSCodium IDE](https://open-vsx.org/extension/JohnnyMorganz/luau-lsp)

:::caution
This assumes you have a variant of the Visual Studio Code IDE, if not - then you can install Luau-Lsp through aftman with the following

```bash
aftman install JohnnyMorganz/luau-lsp
```

using [this guide](https://github.com/JohnnyMorganz/luau-lsp/blob/main/editors/README.md), you may be able to set up the LSP for whatever your configuration is.
:::

---

### Git

Git is primarily a version protocol, websites such as GitHub & GitLab is built around this protocol, allowing developers to upload
versioned code to a repository that anyone can visit and access.

We will need to use Git in order to install the Discord-Luau library into your project.

#### Installation of Git

Git can be installed by following [this guide](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git).

:::note
Git isn't an application, but more of a command line tool, if you're not comfortable with using the command line, there are
git clients out there that can simplify the process of using Git!

I'll link [Git Kraken](https://www.gitkraken.com/) as reference.
:::

## Not Required

The following tools are nice-to-haves, but by all means can be skipped and/or ignored.

### Selene Linter

[Selene](https://github.com/Kampfkarren/selene) allows us to run a [Linter](https://en.wikipedia.org/wiki/Lint_(software)) on our Luau code, this is generally a healthy tool to have if you're going
to be making a large codebase.

#### Installation of Selene

You can install the selene lint through aftman with the following command

```bash
aftman install Kampfkarren/selene
```

### Stylua Formatter

[Stylua](https://github.com/JohnnyMorganz/StyLua) allows us to run a [Code Formatter](https://trunk.io/learn/what-is-a-code-formatter-and-why-would-i-want-to-use-one) on our Luau code, this is also quite healthy
if you're going to either be working in a team, or the codebase is going to become quite large.

#### Installation of Stylua

You can install the Stylua formatter through aftman with the following command

```bash
aftman install JohnnyMorganz/StyLua
```

## Conclusion

You should now have the avaliable tools to start developing a discord application in Discord Luau!

The following is a `aftman.toml` file containing all of the above tools, you can compare what you have to this to ensure everything
is correctly installed!

```toml
# This file lists tools managed by Aftman, a cross-platform toolchain manager.
# For more information, see https://github.com/LPGhatguy/aftman

# To add a new tool, add an entry to this table.
[tools]
lune = "lune-org/lune@0.8.4"
stylua = "JohnnyMorganz/StyLua@0.20.0"
selene = "Kampfkarren/selene@0.27.1"
luau-lsp = "JohnnyMorganz/luau-lsp@1.24.1"
```

Additionally, you should also have the following applications avaliable in the command line:

```bash
git -v
```

```bash
aftman -V
```

and finally, you've installed an IDE, such as Visual Studio Code!
93 changes: 93 additions & 0 deletions src/content/docs/getting-started/installation.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
title: Installation
description: Instructions on how to install and set up the Discord-Luau package.
---

This guide will walk you though installing the Discord-Luau package into an IDE of your choice, enabling you
to start creating Discord Applications!

:::tip
This guide assumes the following;

- You've set up your environment, if you've not already done this, please take a look at [this guide](/getting-started/environment/)
:::

### Context

The Luau language is yet to find it's true package manager, which makes installing Discord-Luau a little bit more complicated
than other languages..

and in order to keep to some sort of standard for installing this as a package, we've gone for the *dreaded*
[Git Submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules) approach.

:::note
If you're aware of a Package Manager that Luau packages can take advantage of, please reach out to us through GitHub issues!

We would LOVE to collaborate and get DiscordLuau onto a Luau package manager.
:::

### Git Submodules

This section will assume you know nothing about Git submodules, *and if so.. oh god forgive me for stress i'm about to cause you.. sorry!*

Jokes aside, Git Submodules are actually a really useful resource for linking git repositories into one another, by doing this, we
allow your code *(which should be a git repository)* to import discord luau *(a git reposoitory)*, and then use this as a package in your
project.

#### Setting up a git repository

Assuming you just have a folder at the moment, and you're in that folder, within your IDE *(I'll be using VSCode as reference)* what
you have is not yet a git repository.

To create a git repository, you'll need to execute the following command in a command line, inside of your project folder:
```bash
git init
```

This should set up a git repository inside of that folder *(if you don't see any new files, or changes, don't worry! Git did create a
`.git` folder, it's normally just hidden by your OS!)*

#### Adding Discord-Luau to your workspace

Assuming you've set up a git repository, add Discord-Luau to your workspace by executing the following in a command line:

```bash
git submodule add https://github.com/DiscordLuau/discord-luau.git DiscordLuau
```

#### Updating Discord-Luau

Assuming you've set up a git repository, and added Discord-Luau as a submodule, you can update Discord-Luau through the following commands

```bash
cd DiscordLuau
git checkout master
git pull
cd ..
```

if we break this down a bit, in our terminal, we're entering the DiscordLuau folder *(which is the git repository for DiscordLuau!)*
then switching from HEAD *(the version you had installed locally)* to `master`, which is the latest version of DiscordLuau that is most updated
and then pulling any changes we don't have, from github, into our repository.

#### I've made changes to Discord-Luau

If you've made changes to Discord-Luau, and you're unable to checkout a different branch, or pull from the remote, i'd suggest
creating a fork of discord-luau, and maintaing that fork.

I will not be going into details on how you'd do that.. one because I suck at git, and two because generally we're going to be going
into more advanced topics that you should learn indepdantly from discord-luau.

---

*Don't make changes to discord-luau, unless you're comfortable with Git!*

#### Removing Discord-Luau

Yeah.. maybe it's time we switch to a package manager, or maybe you just can't update and you'd rather just re-install discord-luau..

well, you can remove the submodule through the following commands:

```bash
git rm DiscordLuau
```
71 changes: 71 additions & 0 deletions src/content/docs/guides/basic.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
title: Basic Application
description: A basic application that demo's getting started with Discord Luau
---

import { Steps } from '@astrojs/starlight/components';
import { Aside } from '@astrojs/starlight/components';

This guide details the steps taken to create your first discord application!

<Steps>

1. Create a new `Application.luau` file

2. Using the DiscordLuau submodule, require the submodule and set up a basic client object

```lua
local DiscordLuau = require("DiscordLuau")

local DiscordSettings = DiscordLuau.SettingsBuilder.new("<DISCORD_TOKEN>")
local DiscordClient = DiscordLuau.DiscordClient.new(DiscordSettings)

DiscordClient:connectAsync():after(function()
print("We've connected to the Discord Websocket! πŸš€")
end)
```

3. Connect to the 'Ready' discord event:

```lua
DiscordClient.eventManager.onReady:connect(function()
print(`{DiscordClient.discordUser.username} is online! πŸŽ‰`)
end)
```

4. Run the Application

```bash
lune run application.luau
```

5. if all goes well, your application should connect to the Discord API and print the above messages!
</Steps>

:::caution
In the case the bot fails to connect, please check that you've toggled your applications intents correctly!

If you need to modify the intents of the Bot from Luau, you can do so with:
```lua
local DiscordSettings = DiscordLuau.SettingsBuilder.new("<DISCORD_TOKEN>", DiscordLuau.IntentsBuilder.fromDefault())
```
:::

<details>
<summary>Complete Code</summary>

```lua
local DiscordLuau = require("DiscordLuau")

local DiscordSettings = DiscordLuau.SettingsBuilder.new("<DISCORD_TOKEN>")
local DiscordClient = DiscordLuau.DiscordClient.new(DiscordSettings)

DiscordClient.eventManager.onReady:connect(function()
print("We've connected to the Discord Websocket! πŸš€")
end)

DiscordClient:connectAsync():after(function()
print("We've connected to the Discord Websocket! πŸš€")
end)
```
</details>

0 comments on commit 0082d64

Please sign in to comment.