-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: implement guides for Discord-Luau
- Loading branch information
Showing
5 changed files
with
349 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule discord-luau
updated
98 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |