diff --git a/DisCatSharp.Docs/articles/basics/bot_account.md b/DisCatSharp.Docs/articles/basics/bot_account.md index 85fd0f51b..5ef2c15c0 100644 --- a/DisCatSharp.Docs/articles/basics/bot_account.md +++ b/DisCatSharp.Docs/articles/basics/bot_account.md @@ -1,91 +1,95 @@ --- uid: basics_bot_account title: Creating a Bot Account --- # Creating a Bot Account ## Create an Application Before you're able to create a [bot account](https://discord.com/developers/docs/topics/oauth2#bots) to interact with the Discord API, you'll need to create a new OAuth2 application. Go to the [Discord Developer Portal](https://discord.com/developers/applications) and click `New Application` at the top right of the page. ![Discord Developer Portal](/images/basics_bot_account_01.png)
You'll then be prompted to enter a name for your application.
![Naming Application](/images/basics_bot_account_02.png "Naming Application") The name of your application will be the name displayed to users when they add your bot to their Discord server.
With that in mind, it would be a good idea for your application name to match the desired name of your bot. -Enter your desired application name into the text box, then hit the `Create` button. +Enter your desired application name into the text box, accept the [Developer Terms of Service](https://discord.com/developers/docs/policies-and-agreements/terms-of-service) and [Developer Policy](https://discord.com/developers/docs/policies-and-agreements/developer-policy) and hit the `Create` button. After you hit `Create`, you'll be taken to the application page for your newly created application. ![Application Page](/images/basics_bot_account_03.png) That was easy, wasn't it? Before you move on, you may want to upload an icon for your application and provide a short description of what your bot will do. As with the name of your application, the application icon and description will be displayed to users when adding your bot. ## Add a Bot Account Now that you have an application created, you'll be able to add a brand new bot account to it. Head on over to the bot page of your application by clicking on `Bot` in the left panel.
From there, click on the `Add Bot` button at the top right of the page. ![Bot Page](/images/basics_bot_account_04.png) Then confirm the creation of the bot account. ![Creation Confirmation](/images/basics_bot_account_05.png) # Using Your Bot Account ## Invite Your Bot Now that you have a bot account, you'll probably want to invite it to a server! A bot account joins a server through a special invite link that'll take users through the OAuth2 flow; you'll probably be familiar with this if you've ever added a public Discord bot to a server. -To get the invite link for your bot, head on over to the OAuth2 page of your application. +To get the invite link for your bot, head on over to the `OAuth2` page of your application and select the `URL Generator` page. -![OAuth2](/images/basics_bot_account_06.png) +![OAuth2 URL Generator](/images/basics_bot_account_06.png "OAuth2 URL Generator")
We'll be using the *OAuth2 URL Generator* on this page.
Simply tick `bot` under the *scopes* panel; your bot invite link will be generated directly below. -![OAuth2 Scopes](/images/basics_bot_account_07.png) +![OAuth2 Scopes](/images/basics_bot_account_07.png "OAuth2 Scopes")
By default, the generated link will not grant any permissions to your bot when it joins a new server.
If your bot requires specific permissions to function, you'd select them in the *bot permissions* panel. ![Permissions](/images/basics_bot_account_08.png "Permissions Panel") The invite link in the *scopes* panel will update each time you change the permissions.
Be sure to copy it again after any changes! ## Get Bot Token Instead of logging in to Discord with a username and password, bot accounts use a long string called a *token* to authenticate. You'll want to retrieve the token for your bot account so you can use it with DisCatSharp. -Head back to the bot page and click on `Click to Reveal Token` just above the `Copy` and `Regenerate` buttons to take a peek at your token. +Head back to the bot page and click on `Reset Token` just below the bot's username field. -![Token Reveal](/images/basics_bot_account_09.png "Token Reveal") +![Token Reset](/images/basics_bot_account_09.png "Token Reset") + +Click on `Yes, do it!` to confirm the reset. + +![Token Reset Confirm](/images/basics_bot_account_10.png "Token Reset Confirmation") Go ahead and copy your bot token and save it somewhere. You'll be using it soon! >[!IMPORTANT] > Handle your bot token with care! Anyone who has your token will have access to your bot account. > Be sure to store it in a secure location and *never* give it to *anybody*. > - > If you ever believe your token has been compromised, be sure to hit the `Regenerate` button (as seen above) to invalidate your old token and get a brand new token. + > If you ever believe your token has been compromised, be sure to hit the `Reset Token` button (as seen above) to invalidate your old token and get a brand new token. ## Write Some Code You've got a bot account set up and a token ready for use.
-Sounds like it's time for you to [write your first bot](xref:basics_first_bot)! \ No newline at end of file +Sounds like it's time for you to [write your first bot](xref:basics_first_bot)! diff --git a/DisCatSharp.Docs/articles/basics/first_bot.md b/DisCatSharp.Docs/articles/basics/first_bot.md index f1e613b5e..8a36d5c9c 100644 --- a/DisCatSharp.Docs/articles/basics/first_bot.md +++ b/DisCatSharp.Docs/articles/basics/first_bot.md @@ -1,227 +1,234 @@ --- uid: basics_first_bot title: Your First Bot --- # Your First Bot >[!NOTE] > This article assumes the following: > * You have [created a bot account](xref:basics_bot_account "Creating a Bot Account") and have a bot token. - > * You have [Visual Studio 2019](https://visualstudio.microsoft.com/vs/) installed on your computer. + > * You have [Visual Studio 2022](https://visualstudio.microsoft.com/vs/) installed on your computer. ## Create a Project Open up Visual Studio and click on `Create a new project` towards the bottom right. ![Visual Studio Start Screen](/images/basics_first_bot_01.png)
-Select `Console App (.NET Core)` then click on the `Next` button. +Select `Console App` then click on the `Next` button. ![New Project Screen](/images/basics_first_bot_02.png)
Next, you'll give your project a name. For this example, we'll name it `MyFirstBot`.
If you'd like, you can also change the directory that your project will be created in. Enter your desired project name, then click on the `Create` button. ![Name Project Screen](/images/basics_first_bot_03.png)
-VoilĂ ! Your project has been created! +Now select `.NET 6.0 (Long-term support)` from the dropdown menu, tick the `Do not use top-level statements` checkbox and click on the `Next` button. + +![Framework Project Screen](/images/basics_first_bot_04.png) -![Visual Studio IDE](/images/basics_first_bot_04.png) +
+VoilĂ ! Your project has been created! +![Visual Studio IDE](/images/basics_first_bot_05.png) ## Install Package Now that you have a project created, you'll want to get DisCatSharp installed. Locate the *solution explorer* on the right side, then right click on `Dependencies` and select `Manage NuGet Packages` from the context menu. -![Dependencies Context Menu](/images/basics_first_bot_05.png) +![Dependencies Context Menu](/images/basics_first_bot_06.png)
You'll then be greeted by the NuGet package manager. Select the `Browse` tab towards the top left, then type `DisCatSharp` into the search text box with the Pre-release checkbox checked **ON**. -![NuGet Package Search](/images/basics_first_bot_06.png) +![NuGet Package Search](/images/basics_first_bot_07.png)
The first results should be the DisCatSharp packages. Package|Description :---: |:---: `DisCatSharp`|Main package; Discord API client. `DisCatSharp.CommandsNext`|Add-on which provides a command framework. `DisCatSharp.Common`|Common tools & converters `DisCatSharp.Interactivity`|Add-on which allows for interactive commands. `DisCatSharp.Lavalink`|Client implementation for [Lavalink](xref:modules_audio_lavalink_setup). Useful for music bots. `DisCatSharp.ApplicationCommands`|Add-on which makes dealing with application commands easier. `DisCatSharp.VoiceNext`|Add-on which enables connectivity to Discord voice channels. `DisCatSharp.VoiceNext.Natives`|Voice next natives.
We'll only need the `DisCatSharp` package for the basic bot we'll be writing in this article.
-Select it from the list then click the `Install` button to the right (after verifying that you will be installing the **latest 4.0 version**). +Select it from the list then click the `Install` button to the right. ![Install DisCatSharp](/images/basics_first_bot_08.png) You're now ready to write some code! ## First Lines of Code DisCatSharp implements [Task-based Asynchronous Pattern](https://docs.microsoft.com/en-us/dotnet/standard/asynchronous-programming-patterns/consuming-the-task-based-asynchronous-pattern). Because of this, the majority of DisCatSharp methods must be executed in a method marked as `async` so they can be properly `await`ed. Due to the way the compiler generates the underlying [IL](https://en.wikipedia.org/wiki/Common_Intermediate_Language) code, marking our `Main` method as `async` has the potential to cause problems. As a result, we must pass the program execution to an `async` method. Head back to your *Program.cs* tab and empty the `Main` method by deleting line 9. ![Code Editor](/images/basics_first_bot_09.png) Now, create a new `static` method named `MainAsync` beneath your `Main` method. Have it return type `Task` and mark it as `async`. After that, add `MainAsync().GetAwaiter().GetResult();` to your `Main` method. ```cs static void Main(string[] args) { MainAsync().GetAwaiter().GetResult(); } static async Task MainAsync() { } ``` If you typed this in by hand, Intellisense should have generated the required `using` directive for you.
However, if you copy-pasted the snippet above, VS will complain about being unable to find the `Task` type. Hover over `Task` with your mouse and click on `Show potential fixes` from the tooltip. ![Error Tooltip](/images/basics_first_bot_10.png) Then apply the recommended solution. ![Solution Menu](/images/basics_first_bot_11.png)
We'll now create a new `DiscordClient` instance in our brand new asynchronous method. Create a new variable in `MainAsync` and assign it a new `DiscordClient` instance, then pass an instance of `DiscordConfiguration` to its constructor. Create an object initializer for `DiscordConfiguration` and populate the `Token` property with your bot token then set the `TokenType` property to `TokenType.Bot`. -Next add the `Intents` Property and Populated it with the @DisCatSharp.DiscordIntents.AllUnprivileged value. These Intents +Next add the `Intents` Property and Populated it with the @DisCatSharp.DiscordIntents.AllUnprivileged and DiscordIntents.MessageContent values. +The message content intent must be enabled in the developer portal as well. +These Intents are required for certain Events to be fired. Please visit this [article](xref:beyond_basics_intents) for more information. ```cs var discord = new DiscordClient(new DiscordConfiguration() { Token = "My First Token", TokenType = TokenType.Bot, - Intents = DiscordIntents.AllUnprivileged + Intents = DiscordIntents.AllUnprivileged | DiscordIntents.MessageContent }); ``` >[!WARNING] > We hard-code the token in the above snippet to keep things simple and easy to understand. > > Hard-coding your token is *not* a smart idea, especially if you plan on distributing your source code. > Instead you should store your token in an external medium, such as a configuration file or environment variable, and read that into your program to be used with DisCatSharp. Follow that up with `await discord.ConnectAsync();` to connect and login to Discord, and `await Task.Delay(-1);` at the end of the method to prevent the console window from closing prematurely. ```cs var discord = new DiscordClient(); await discord.ConnectAsync(); await Task.Delay(-1); ``` As before, Intellisense will have auto generated the needed `using` directive for you if you typed this in by hand.
If you've copied the snippet, be sure to apply the recommended suggestion to insert the required directive. If you hit `F5` on your keyboard to compile and run your program, you'll be greeted by a happy little console with a single log message from DisCatSharp. Woo hoo! ![Program Console](/images/basics_first_bot_12.png) ## Spicing Up Your Bot Right now our bot doesn't do a whole lot. Let's bring it to life by having it respond to a message! Hook the `MessageCreated` event fired by `DiscordClient` with a [lambda](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/lambda-expressions).
Mark it as `async` and give it two parameters: `s` and `e`. ```cs discord.MessageCreated += async (s, e) => { }; ``` Then, add an `if` statement into the body of your event lambda that will check if `e.Message.Content` starts with your desired trigger word and respond with a message using `e.Message.RespondAsync` if it does. For this example, we'll have the bot to respond with *pong!* for each message that starts with *ping*. ```cs discord.MessageCreated += async (s, e) => { if (e.Message.Content.ToLower().StartsWith("ping")) await e.Message.RespondAsync("pong!"); }; ``` ## The Finished Product Your entire program should now look like this: ```cs using System; using System.Threading.Tasks; using DisCatSharp; namespace MyFirstBot { class Program { static void Main(string[] args) { MainAsync().GetAwaiter().GetResult(); } static async Task MainAsync() { var discord = new DiscordClient(new DiscordConfiguration() { - Token = "My First Token", - TokenType = TokenType.Bot + Token = "My First Token", + TokenType = TokenType.Bot, + Intents = DiscordIntents.AllUnprivileged | DiscordIntents.MessageContent }); discord.MessageCreated += async (s, e) => { if (e.Message.Content.ToLower().StartsWith("ping")) await e.Message.RespondAsync("pong!"); }; await discord.ConnectAsync(); await Task.Delay(-1); } } } ``` Hit `F5` to run your bot, then send *ping* in any channel your bot account has access to.
Your bot should respond with *pong!* for each *ping* you send. Congrats, your bot now does something! ![Bot Response](/images/basics_first_bot_13.png) ## Further Reading Now that you have a basic bot up and running, you should take a look at the following: * [Events](xref:beyond_basics_events) * [CommandsNext](xref:modules_commandsnext_intro) * [ApplicationCommands](xref:modules_application_commands_intro) diff --git a/DisCatSharp.Docs/articles/modules/audio/voicenext/prerequisites.md b/DisCatSharp.Docs/articles/modules/audio/voicenext/prerequisites.md index 24b72042c..fdf4e504a 100644 --- a/DisCatSharp.Docs/articles/modules/audio/voicenext/prerequisites.md +++ b/DisCatSharp.Docs/articles/modules/audio/voicenext/prerequisites.md @@ -1,41 +1,42 @@ --- uid: modules_audio_voicenext_prerequisites title: VoiceNext Prerequisites --- # VoiceNext Prerequisites -> Note: We highly suggest using the [DisCatSharp.Lavalink](xref:modules_audio_lavalink_configuration) package for audio playback. It is much easier to use and has a lot of features that VoiceNext does not have. +> [!INFO] + > We highly suggest using the [DisCatSharp.Lavalink](xref:modules_audio_lavalink_configuration) package for audio playback. It is much easier to use and has a lot of features that VoiceNext does not have. ## Required Libraries VoiceNext depends on the [libsodium](https://github.com/jedisct1/libsodium) and [Opus](https://opus-codec.org/) libraries to decrypt and process audio packets.
Both *must* be available on your development and host machines otherwise VoiceNext will *not* work. ### Windows When installing VoiceNext though NuGet, an additional package containing the native Windows binaries will automatically be included with **no additional steps required**. However, if you are using DisCatSharp from source or without a NuGet package manager, you must manually [download](xref:natives) the binaries and place them at the root of your working directory where your application is located. ### MacOS Native libraries for Apple's macOS can be installed using the [Homebrew](https://brew.sh) package manager: ```console $ brew install opus libsodium ``` ### Linux #### Debian and Derivatives Opus package naming is consistent across Debian, Ubuntu, and Linux Mint. ```bash sudo apt-get install libopus0 libopus-dev ``` Package naming for *libsodium* will vary depending on your distro and version: Distributions|Terminal Command :---:|:---: Ubuntu 18.04+, Debian 10+|`sudo apt-get install libsodium23 libsodium-dev` Linux Mint, Ubuntu 16.04, Debian 9 |`sudo apt-get install libsodium18 libsodium-dev` Debian 8|`sudo apt-get install libsodium13 libsodium-dev` diff --git a/DisCatSharp.Docs/images/basics_first_bot_07.png b/DisCatSharp.Docs/images/_basics_first_bot_07.png similarity index 100% copy from DisCatSharp.Docs/images/basics_first_bot_07.png copy to DisCatSharp.Docs/images/_basics_first_bot_07.png diff --git a/DisCatSharp.Docs/images/basics_bot_account_01.png b/DisCatSharp.Docs/images/basics_bot_account_01.png index 4bc918bdb..5596901d2 100644 Binary files a/DisCatSharp.Docs/images/basics_bot_account_01.png and b/DisCatSharp.Docs/images/basics_bot_account_01.png differ diff --git a/DisCatSharp.Docs/images/basics_bot_account_02.png b/DisCatSharp.Docs/images/basics_bot_account_02.png index a301f725a..436ded4c3 100644 Binary files a/DisCatSharp.Docs/images/basics_bot_account_02.png and b/DisCatSharp.Docs/images/basics_bot_account_02.png differ diff --git a/DisCatSharp.Docs/images/basics_bot_account_03.png b/DisCatSharp.Docs/images/basics_bot_account_03.png index 04f818fc7..af85b27cc 100644 Binary files a/DisCatSharp.Docs/images/basics_bot_account_03.png and b/DisCatSharp.Docs/images/basics_bot_account_03.png differ diff --git a/DisCatSharp.Docs/images/basics_bot_account_04.png b/DisCatSharp.Docs/images/basics_bot_account_04.png index 994674570..77f7a356b 100644 Binary files a/DisCatSharp.Docs/images/basics_bot_account_04.png and b/DisCatSharp.Docs/images/basics_bot_account_04.png differ diff --git a/DisCatSharp.Docs/images/basics_bot_account_05.png b/DisCatSharp.Docs/images/basics_bot_account_05.png index c802b4cd1..52c002845 100644 Binary files a/DisCatSharp.Docs/images/basics_bot_account_05.png and b/DisCatSharp.Docs/images/basics_bot_account_05.png differ diff --git a/DisCatSharp.Docs/images/basics_bot_account_06.png b/DisCatSharp.Docs/images/basics_bot_account_06.png index e5fbf3cf4..370f3126e 100644 Binary files a/DisCatSharp.Docs/images/basics_bot_account_06.png and b/DisCatSharp.Docs/images/basics_bot_account_06.png differ diff --git a/DisCatSharp.Docs/images/basics_bot_account_07.png b/DisCatSharp.Docs/images/basics_bot_account_07.png index 3048be982..ca6b3fed6 100644 Binary files a/DisCatSharp.Docs/images/basics_bot_account_07.png and b/DisCatSharp.Docs/images/basics_bot_account_07.png differ diff --git a/DisCatSharp.Docs/images/basics_bot_account_08.png b/DisCatSharp.Docs/images/basics_bot_account_08.png index d86d27443..b46e28e52 100644 Binary files a/DisCatSharp.Docs/images/basics_bot_account_08.png and b/DisCatSharp.Docs/images/basics_bot_account_08.png differ diff --git a/DisCatSharp.Docs/images/basics_bot_account_09.png b/DisCatSharp.Docs/images/basics_bot_account_09.png index 3ef21b80a..ea2a174ac 100644 Binary files a/DisCatSharp.Docs/images/basics_bot_account_09.png and b/DisCatSharp.Docs/images/basics_bot_account_09.png differ diff --git a/DisCatSharp.Docs/images/basics_bot_account_10.png b/DisCatSharp.Docs/images/basics_bot_account_10.png new file mode 100644 index 000000000..db62792b5 Binary files /dev/null and b/DisCatSharp.Docs/images/basics_bot_account_10.png differ diff --git a/DisCatSharp.Docs/images/basics_first_bot_01.png b/DisCatSharp.Docs/images/basics_first_bot_01.png index 1585521dd..6daf95d21 100644 Binary files a/DisCatSharp.Docs/images/basics_first_bot_01.png and b/DisCatSharp.Docs/images/basics_first_bot_01.png differ diff --git a/DisCatSharp.Docs/images/basics_first_bot_02.png b/DisCatSharp.Docs/images/basics_first_bot_02.png index a17cc518b..a50d12b99 100644 Binary files a/DisCatSharp.Docs/images/basics_first_bot_02.png and b/DisCatSharp.Docs/images/basics_first_bot_02.png differ diff --git a/DisCatSharp.Docs/images/basics_first_bot_03.png b/DisCatSharp.Docs/images/basics_first_bot_03.png index a0ae365ac..c8f144092 100644 Binary files a/DisCatSharp.Docs/images/basics_first_bot_03.png and b/DisCatSharp.Docs/images/basics_first_bot_03.png differ diff --git a/DisCatSharp.Docs/images/basics_first_bot_04.png b/DisCatSharp.Docs/images/basics_first_bot_04.png index 908055fe8..c806c6d83 100644 Binary files a/DisCatSharp.Docs/images/basics_first_bot_04.png and b/DisCatSharp.Docs/images/basics_first_bot_04.png differ diff --git a/DisCatSharp.Docs/images/basics_first_bot_05.png b/DisCatSharp.Docs/images/basics_first_bot_05.png index 4fa997e66..e5291b7a6 100644 Binary files a/DisCatSharp.Docs/images/basics_first_bot_05.png and b/DisCatSharp.Docs/images/basics_first_bot_05.png differ diff --git a/DisCatSharp.Docs/images/basics_first_bot_06.png b/DisCatSharp.Docs/images/basics_first_bot_06.png index 49403b7b3..718404c27 100644 Binary files a/DisCatSharp.Docs/images/basics_first_bot_06.png and b/DisCatSharp.Docs/images/basics_first_bot_06.png differ diff --git a/DisCatSharp.Docs/images/basics_first_bot_07.png b/DisCatSharp.Docs/images/basics_first_bot_07.png index 1dc2f5810..7d820be0d 100644 Binary files a/DisCatSharp.Docs/images/basics_first_bot_07.png and b/DisCatSharp.Docs/images/basics_first_bot_07.png differ diff --git a/DisCatSharp.Docs/images/basics_first_bot_08.png b/DisCatSharp.Docs/images/basics_first_bot_08.png index d431e8ae9..f6b8fc736 100644 Binary files a/DisCatSharp.Docs/images/basics_first_bot_08.png and b/DisCatSharp.Docs/images/basics_first_bot_08.png differ diff --git a/DisCatSharp.Docs/images/basics_first_bot_09.png b/DisCatSharp.Docs/images/basics_first_bot_09.png index eb54d7fe2..caac19d9d 100644 Binary files a/DisCatSharp.Docs/images/basics_first_bot_09.png and b/DisCatSharp.Docs/images/basics_first_bot_09.png differ diff --git a/DisCatSharp.Docs/images/basics_first_bot_10.png b/DisCatSharp.Docs/images/basics_first_bot_10.png index a80e1732e..2ebb7c446 100644 Binary files a/DisCatSharp.Docs/images/basics_first_bot_10.png and b/DisCatSharp.Docs/images/basics_first_bot_10.png differ diff --git a/DisCatSharp.Docs/images/basics_first_bot_11.png b/DisCatSharp.Docs/images/basics_first_bot_11.png index 73a9bbaab..ddbaa9db9 100644 Binary files a/DisCatSharp.Docs/images/basics_first_bot_11.png and b/DisCatSharp.Docs/images/basics_first_bot_11.png differ diff --git a/DisCatSharp.Docs/images/basics_first_bot_13.png b/DisCatSharp.Docs/images/basics_first_bot_13.png index 68333989c..77e0f27fd 100644 Binary files a/DisCatSharp.Docs/images/basics_first_bot_13.png and b/DisCatSharp.Docs/images/basics_first_bot_13.png differ