Galsol.DiscordBot 1.1.3

dotnet add package Galsol.DiscordBot --version 1.1.3                
NuGet\Install-Package Galsol.DiscordBot -Version 1.1.3                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Galsol.DiscordBot" Version="1.1.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Galsol.DiscordBot --version 1.1.3                
#r "nuget: Galsol.DiscordBot, 1.1.3"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Galsol.DiscordBot as a Cake Addin
#addin nuget:?package=Galsol.DiscordBot&version=1.1.3

// Install Galsol.DiscordBot as a Cake Tool
#tool nuget:?package=Galsol.DiscordBot&version=1.1.3                

Discord Bot

By Galsol

2018

If you have some knowledge in the topic, you may scroll down for shortened, non-detailed version on how to use.


This easy to use library offers fast, yet powerful way to create discord bots.

1. Creating the bot

First step is creating the bot account, To do so visit: https://discordapp.com/developers/applications/ Create new application, give it the best name you could find, a picture that will be remembered for ages and feed some cookies. In the 'Bot' tab (left) click "Add bot". We basically got a working bot account now. Hooray! \o/

2. Linking the bot to your server (or anyone else)

From 'General Information' copy the client id and copy it. Replace the "[Client_ID HERE]" from the link below. https://discordapp.com/api/oauth2/authorize?client_id=[Client_id HERE]&scope=bot&permissions=67584 Go to the link, enter your credentials and choose the server you wish to add the bot to.

3. Setting up the bot in C#

To set up the bot, in your Main function write:

Bot bot = new Bot("fileName.json", "botToken");

Note that you may replace fileName with a file name of your choice, for example channelID. Replace botToken with your bot token (Achieved from the 'Bot' tab in the developer portal), and run your program.

This should create a new JSON file in your run directory (default: project folder → bin → Debug/Release). Edit this JSON with your text editor of choice, insert between the 2 empty " the id of the room you want your bot to operate in. Easiest way to obtain the ID is open Discord, go to 'User Settings' → 'Appearance' and enable 'Developer Mode'. You can then simply right click the chat room and click 'Copy ID'. Do this with serverID as well, by right clicking the server in which the bot will operate. The end-result JSON file should look something like this:

{
	"channelId": "231239812389123912"
	"serverId": "12312312313213212"
}
4. Programming your bot

Now you can start programming your bot. The way this works is: after creating your bot, write

bot.MessageCreated += __Your Function__

In Visual Studio it is enough to write bot.MessageCreated += and then hit [TAB]. Visual Studio auto-complete will auto-do its magic!

Examples:

	bot.MessageCreated += MyFunc;
}
static void MyFunc(object sender, MessageEventArgs e)
{
...
}
	bot.MessageCreated += (object sender, MessageEventArgs e) => {
	...
	};
}
5. Connecting your bot

Next (and final of the setup) is connecting your bot to the online world! Simple as that, the only thing you need to do is

bot.Connect(Bot.state.[], [game], Bot.status.[]);

The state and game are what will be displayed below the name of the bot. For example:

bot.Connect(Bot.state.Playing, "C#", Bot.status.Online);

Will appear on discord like: alternate text is missing from this package README image

Short Version

Step 1 .Create your bot at Developer Portal

Step 2. Authorize it and choose your server https://discordapp.com/api/oauth2/authorize?client_id={Add client ID here}&scope=bot&permissions=67584 (Make sure to add the client id of the bot in the url)

Step 3 .Create a JSON file in the same folder of your executable with a "channel_id" as key and as value a string that contains the ID of the room that you want your bot to operate in.

In Main() create a new Bot class:

Bot bot = new Bot("jsonFileName", "YourBotToken");

Add event handler to bot.MessageCreated:

bot.MessageCreated += *yourFunction*;

Make your bot online!

bot.Connect(Bot.state, game, Bot.status);

Congratulations! Your bot is now operating!

Now to the cool stuff... Programming it. Below is the documentation of how to program it. Dont forget to using DiscordBot at the start of the file! If it doesn't find DiscordBot, right click on references in solution explorer → add a reference and enable DiscordBot.dll


Function and objects documentation

DiscordBot class

bot.postMessage(string content) - Posts message in the room MessageEventArgs - contains Message object as msg Message - Includes every information about the message, i.e content, Author, timestamp etc. Author - Contains information about message author. i.e username, id.

Files class

save(fileName, Dictionary) - Saves the dictionary of <string, string> or <string, int> to the fileName.json read(fileName) - Reads and returns a dictionary<string, string> from fileName.json readI(fileName) - Reads and returns a dictionary<string, int> from fileName.json All json files are stored at executablePath/Data/

Product Compatible and additional computed target framework versions.
.NET Framework net is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.3 732 7/12/2019
1.1.2 567 7/12/2019
1.1.1 562 7/12/2019
1.1.0 806 9/19/2018