Skip to content
This repository was archived by the owner on Oct 2, 2025. It is now read-only.

Creating a custom extension

Maik Riedlsperger edited this page Nov 15, 2019 · 1 revision

The bot is almost fully modular and allows you to make a custom extension in the blink of an eye.

To create an extension, you'll need two things:

  • The extensions source (.dll)
  • The sql command, to add the extensions trigger to the database (.sql)

Let's start with the source code. You will need to import Discord C# to create an extension. It can be imported via NuGet.

//Importing standard C# libraries
using System;
//Importing Discord C# functions
using Discord.WebSocket;

//Your class
public class HelloWorld
{
	//The message, that was sent from the user
	private SocketMessage Msg;

	//You'll ALWAYS need a constructor, that accepts a SocketMessage, to create an extension
	public HelloWorld(SocketMessage message)
	{
		Msg = message;
	}

	//This is the function, that will be triggered, when the user inputs the according command into Discord
	//These functions MUST return a String.
	public String SayHello()
	{
		//In my case this would return "Hello @ADarkHero!"
		return "Hello " + "<@" + Msg.Author.Id + ">!";
	}
}

Quite simple, isn't it? The most important things are the constructor and the method, that has to return a String. Everything else is up to you.

When your code is done, you can build it as .dll. Next you'll have to put the .dll in the /ext directory of the bot. The bot automatically loads all dlls in that directory. Files in other directories will be ignored. Files that are not .dll will also be ignored.


The next step is the sql part. This tells your bot, when your command should trigger.

INSERT INTO commands 
(
	CommandName, -- The command that the user has to input to trigger a function; Input the CommandName without the DicordChar (by default !)
	CommandComment, -- A comment, that will be displayed, in the command overview
	CommandType, -- The type of the command. 0 => Simple; 100 => Regex; 101 => Complex
	CommandRegex, -- You'll need to fill this, if a regex should trigger your function
	CommandObject, -- Name of the object, that should be generated, when the Discord-user inputs a command
	CommandFunction, -- Name of the function, that should be triggered, when the Discord-user inputs a command (without braces)
	CommandAlias, -- If your function should be triggered by multiple commands, you can set an alias, to not show all of the commands in the command overview
	CommandRights -- What rights are needed to execute the command? null => No rights; 1 => Only server admins can use it.
)
VALUES
(
	"HelloWorld",
	"Displays a Hello World message.",
	101,
	null,
	"HelloWorld",
	"SayHello",
	null,
	null
)

You'll need to execute this sql code in the database.db SQLite database.

You're done now! Your custom extension is ready to rock!

Overview

Installation

Quick setup guide

Extended setup guide

Creating own stuff

Creating a custom extension

Clone this wiki locally