DSharpPlus Example Bots
These are example bots for DSharpPlus library.
They are basic bots which are meant to introduce you to various aspects of the DSharpPlus library.
- Example 1: Introduces very basic bot skeleton. The bot simply connects to guilds, and prints some information to console.
- Example 2: Introduces CommandsNext. This bot also responds to several commands, as well as presents several CNext concepts and examples of use.
- Example 3: Introduces Interactivity. This bot has several commands that interact with the user in different ways. Presented are several examples of use.
- Example 4: Introduces VoiceNext. This bot has the ability to connect to voice channels and play music in them. Presented is a simple bot that broadcasts audio from specified file in a queued manner.
- Example 5: Demonstrates a bot with a Windows Forms UI. Presented is a way to run a bot without deadlocking the entire application, as well as properly dispatching the events to the UI.
- Example 6: Demonstrates a bot with a Windows Presentation Foundation (WPF) UI. Presented is a way to run a bot without deadlocking the entire application, as well as properly dispatching the events to the UI.
These projects were made using Visual Studio 2017, and they target .NET Core 2.0. You will need one of the following to open and build the projects:
- Visual Studio 2017 Community with .NET Core cross-platform development installed.
- Visual Studio Code with C# extension.
You will also need to install .NET Core 2.0 SDK in both cases.
How to run the bot?
In order to run the bots, you must first create an application for them, build the bots, then configure them.
Create the application
- Go to my applications page on Discord Developer portal.
- Press the new app button.
- New app page will open. Enter your bot's name in the app name field (1), and its description in the description field (2).
- You can optionally give it an avatar by pressing on the avatar button (3).
- When you're done, press the create app button.
- When the app is created, press the create bot user button.
- Once this is done, you will need to copy the bot's token. Under app bot user, there's a token field, press click to reveal and copy the resulting value.
Building the project and configuring the bot
- Open the project, select the startup bot, and compile it.
- Go to
<project path>, and copy the
- Now go to
nis the selected example), paste that file here.
- Open it with Notepad. Replace the placeholder values (do not remove the quotes) with your actual token and command prefix. Save it.
- Our bot is now configured, but we need to add it to our server first.
Adding the bot to your server
- Go back to your app page, and copy your bot's client ID.
- Go to
- On the page, select your server (1), and press authorize (2).
- Done! You can now run the bot!
Running the bots
- Go back to the IDE and hit Debug.
- Congratulations! Your bot is running!
Note on WinForms and WPF examples
Windows Forms (WinForms), Windows Presentation Foundation (WPF), and Universal Windows Platform (UWP) are not officially supported ways of running your bot. These examples exist for educational purposes only.
We will not provide support for running bots through WinForms, WPF, UWP, or any other UI framework, especially non-asynchronous one.
If you require a non-console or non-Discord interface for your bot, consider an ASP.NET or ASP.NET Core application, as these at least offer support for asynchronous code.
Where to now?
You might want to play around with the examples, perhaps modify them a bit.
You can find the documentation for DSharpPlus over here.
If you want to get more help, join the unofficial Discord API server, and look for #dotnet_dsharpplus channel.