An example bot directory for DiscordSharpPlus library. Contains C# and VB.NET examples.
Switch branches/tags
Nothing to show
Clone or download
Latest commit decf677 Oct 16, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
DSPlus.Examples.CSharp.Ex01 Added VB.NET examples, and updated C# examples. Oct 7, 2017
DSPlus.Examples.CSharp.Ex02 Added example 5: WinForms. Fixed copyright notices. Oct 15, 2017
DSPlus.Examples.CSharp.Ex03 Added VB.NET examples, and updated C# examples. Oct 7, 2017
DSPlus.Examples.CSharp.Ex04 Added example 5: WinForms. Fixed copyright notices. Oct 15, 2017
DSPlus.Examples.CSharp.Ex05 Added a C# WPF example. Oct 16, 2017
DSPlus.Examples.CSharp.Ex06 Added VB.NET WPF example. Cleaned up and fixed other examples. Oct 16, 2017
DSPlus.Examples.Vb.Ex01 Added VB.NET examples, and updated C# examples. Oct 7, 2017
DSPlus.Examples.Vb.Ex02 Added example 5: WinForms. Fixed copyright notices. Oct 15, 2017
DSPlus.Examples.Vb.Ex03 Added example 5: WinForms. Fixed copyright notices. Oct 15, 2017
DSPlus.Examples.Vb.Ex04 Added example 5: WinForms. Fixed copyright notices. Oct 15, 2017
DSPlus.Examples.Vb.Ex05 Added VB.NET WPF example. Cleaned up and fixed other examples. Oct 16, 2017
DSPlus.Examples.Vb.Ex06 Added VB.NET WPF example. Cleaned up and fixed other examples. Oct 16, 2017
.gitattributes Add .gitignore and .gitattributes. Mar 6, 2017
.gitignore Updated .gitignore Jun 23, 2017
DSPlus.Examples.sln Added VB.NET WPF example. Cleaned up and fixed other examples. Oct 16, 2017
LICENSE.txt Add project files. Mar 6, 2017
NOTICE.txt Add project files. Mar 6, 2017
README.md Updated README. Oct 16, 2017
config.json Updated README Oct 7, 2017

README.md

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 directory

  • 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.

Requirements

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:

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

  1. Go to my applications page on Discord Developer portal.
  2. Press the new app button.
  3. 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).
  4. When you're done, press the create app button.
  5. When the app is created, press the create bot user button.
  6. 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

  1. Open the project, select the startup bot, and compile it.
  2. Go to <project path>, and copy the config.json file there.
  3. Now go to DSPlus.Examples.<language>.Ex0n (where n is the selected example), paste that file here.
  4. Open it with Notepad. Replace the placeholder values (do not remove the quotes) with your actual token and command prefix. Save it.
  5. Our bot is now configured, but we need to add it to our server first.

Adding the bot to your server

  1. Go back to your app page, and copy your bot's client ID.
  2. Go to https://discordapp.com/oauth2/authorize?client_id=your_app_id_here&scope=bot&permissions=0.
  3. On the page, select your server (1), and press authorize (2).
  4. Done! You can now run the bot!

Running the bots

  1. Go back to the IDE and hit Debug.
  2. 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.

Also check out