Workshop.DiscordBot
1.2.0
This package provides the basic building blocks for creating a Discord Bot with Discord.Net.
Get your bot online with less than 5 lines of code. All you need to worry about is building your commands!
Install-Package Workshop.DiscordBot -Version 1.2.0
dotnet add package Workshop.DiscordBot --version 1.2.0
<PackageReference Include="Workshop.DiscordBot" Version="1.2.0" />
paket add Workshop.DiscordBot --version 1.2.0
#r "nuget: Workshop.DiscordBot, 1.2.0"
Build-A-Bot Workshop
The Build-A-Bot Workshop is a quick and easy way for you to get started building your own Discord Bot.
Getting your bot online is as simple as:
Imports Workshop.DiscordBot
Namespace VB.Example
Module Program
Sub Main(args As String())
'Create an instance of DiscordBot.
'Provide the token file filename and a bot prefix.
Dim simpleBot = New DiscordBot(New BaseBotConfig("token.txt", "/"))
'Start the bot!
simpleBot.StartAsync().GetAwaiter().GetResult() 'Log-in & connect to Discord
End Sub
End Module
End Namespace
using Workshop.DiscordBot;
namespace CSharp.Example
{
class Program
{
private static void Main(string[] args)
{
//Create an instance of DiscordBot.
//Provide the token file filename and a bot prefix.
//Call StartAsync to log-in and connect to Discord
new DiscordBot(new BaseBotConfig("token.txt", "/")).StartAsync().GetAwaiter().GetResult();
}
}
}
Your bot is now onine and listening for commands (any message prefixed with /
, for this example, or a bot mention).
NOTE!
This project uses the Discord.Net wrapper for interfacing with the Discord API.
So, it'll propbably be a good idea to get familiar with their documentation for actually creating your commands.
That said, there is a WorkshopModule
that can be used to replace Discord.Net ModuleBase
and extend the command module funcationality.
Getting Started
Installation
Release builds are available from Nuget
Initial Visual Studio Project
- Create a new project (preferably a .Net Core Console Application)
- Install the Workshop.DiscordBot nuget package via the Visual Studio Packet Manager
- Follow the code snippet above to get connected
- Profit?
Take a look at the Examples provided.
SampleBot_Basic should be enough to give you an idea of adding commands
, services
and custom typereaders
(if needed).
Things to Note
Auto-magic management
- Dependency Injection: An
IServiceProvider
is included for storing and retrieving services. - Adding Services: Classes decorated with the
ServiceAttribute
are automatically loaded into theServiceCollection
. - Initializing Services on Startup: The
InitializeAttribute
can be used to instantiate a service on startup (if necessary). - Adding Commands: The Discord.Net Command Service is the expected approach for creating commands.
All modules tha inherit from either Discord.Net'sModuleBase
or fromWorkshopModule
, are automatically loaded into the providedCommandService
. - Registering Type Readers: Custom Type Readers should be decorated with the
TypeReaderAttribute
.
This allows them to be automatically added to theCommandService
.
Command Module Extension
The WorkshopModule
overrides the ModuleBase
provided by Discord.Net and includes additional helper methods for working with commands.
Utilizing the InteractiveService
from Discord.Addon.Interactive, the WorkshopModule
also assists with adding interactivity to your bot commands.
Basic methods are provided for both interactive messages and interactive reactions. See the SampleBot_Interactive for usage examples.
Build-A-Bot Workshop
The Build-A-Bot Workshop is a quick and easy way for you to get started building your own Discord Bot.
Getting your bot online is as simple as:
Imports Workshop.DiscordBot
Namespace VB.Example
Module Program
Sub Main(args As String())
'Create an instance of DiscordBot.
'Provide the token file filename and a bot prefix.
Dim simpleBot = New DiscordBot(New BaseBotConfig("token.txt", "/"))
'Start the bot!
simpleBot.StartAsync().GetAwaiter().GetResult() 'Log-in & connect to Discord
End Sub
End Module
End Namespace
using Workshop.DiscordBot;
namespace CSharp.Example
{
class Program
{
private static void Main(string[] args)
{
//Create an instance of DiscordBot.
//Provide the token file filename and a bot prefix.
//Call StartAsync to log-in and connect to Discord
new DiscordBot(new BaseBotConfig("token.txt", "/")).StartAsync().GetAwaiter().GetResult();
}
}
}
Your bot is now onine and listening for commands (any message prefixed with /
, for this example, or a bot mention).
NOTE!
This project uses the Discord.Net wrapper for interfacing with the Discord API.
So, it'll propbably be a good idea to get familiar with their documentation for actually creating your commands.
That said, there is a WorkshopModule
that can be used to replace Discord.Net ModuleBase
and extend the command module funcationality.
Getting Started
Installation
Release builds are available from Nuget
Initial Visual Studio Project
- Create a new project (preferably a .Net Core Console Application)
- Install the Workshop.DiscordBot nuget package via the Visual Studio Packet Manager
- Follow the code snippet above to get connected
- Profit?
Take a look at the Examples provided.
SampleBot_Basic should be enough to give you an idea of adding commands
, services
and custom typereaders
(if needed).
Things to Note
Auto-magic management
- Dependency Injection: An
IServiceProvider
is included for storing and retrieving services. - Adding Services: Classes decorated with the
ServiceAttribute
are automatically loaded into theServiceCollection
. - Initializing Services on Startup: The
InitializeAttribute
can be used to instantiate a service on startup (if necessary). - Adding Commands: The Discord.Net Command Service is the expected approach for creating commands.
All modules tha inherit from either Discord.Net'sModuleBase
or fromWorkshopModule
, are automatically loaded into the providedCommandService
. - Registering Type Readers: Custom Type Readers should be decorated with the
TypeReaderAttribute
.
This allows them to be automatically added to theCommandService
.
Command Module Extension
The WorkshopModule
overrides the ModuleBase
provided by Discord.Net and includes additional helper methods for working with commands.
Utilizing the InteractiveService
from Discord.Addon.Interactive, the WorkshopModule
also assists with adding interactivity to your bot commands.
Basic methods are provided for both interactive messages and interactive reactions. See the SampleBot_Interactive for usage examples.
Dependencies
-
.NETCoreApp 2.0
- Discord.Addons.Interactive (>= 2.0.0-dev-00011)
- Discord.Net (>= 2.0.1)
- Microsoft.Extensions.DependencyInjection (>= 2.2.0)
- Workshop.PluginsManager (>= 1.1.0)
- Workshop.Tools (>= 1.0.0)
Used By
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.