From 1a39eaf102a8f82296a4ae651501a583add406f8 Mon Sep 17 00:00:00 2001 From: Wizzy69 Date: Thu, 5 May 2022 22:14:00 +0300 Subject: [PATCH] Update README.md --- README.md | 50 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 84b936d..07dbb1c 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,20 @@ # DiscordBotWithAPI +This is a Discord Bot made with C# that accepts plugins as extensions for more commands and events. All basic commands are built in already in the PluginManager class library. +This project is based on .NET 6 (C#) and [Discord.Net](https://github.com/discord-net/Discord.Net) + + +## Plugins +#### Requirements: +- [Visual Studio](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Community&channel=Release&version=VS2022&source=VSLandingPage&cid=2030&passive=false) +- .NET 6 (downloaded with Visual Studio) Plugin Types: 1. Commands 2. Events -## How to create a plugin -1. Commands
+### How to create a plugin + First of all, Create a new project (class library) in Visual Studio. ![Imgur Image](https://i.imgur.com/KUqzKsB.png) ![Imgur Image](https://i.imgur.com/JzpEViR.png) @@ -14,6 +22,10 @@ First of all, Create a new project (class library) in Visual Studio. ![Imgur Image](https://i.imgur.com/ceaVR2R.png) ![Imgur Image](https://i.imgur.com/UMSitk4.png) ![Imgur Image](https://i.imgur.com/GEjShdl.png) + +1. Commands +Commands are loaded when all plugins are loaded into memory. When an user executes the command, only then the Execute function is called. +Commands are plugins that allow users to interact with them. Here is an example of class that is a command class ```cs using Discord.Commands; @@ -49,7 +61,7 @@ namespace CMD_Utils } ``` -#### Definitions: +#### Code description: - Command - The keyword that triggers the execution for the command. This is what players must type in order to execute your command - Description - The description of your command. Can be anything you like - Usage - The usage of your command. This is what `help [Command]` command will display @@ -68,3 +80,35 @@ Then, reload bot and execute command `lp` in bot's console. The plugin should be there is something wrong in your command's code. 2. Events + +Events are loaded when all plugins are loaded. At the moment when they are loaded, the Start function is called. +Events are used if you want the bot to do something when something happens in server. The following example shows you how to catch when a user joins the server +and send to that user a DM message with `Welcome to server !`. + +```cs +using PluginManager.Others; +using PluginManager.Interfaces; + +public class OnUserJoin : DBEvent +{ + public string name => "MyEvent"; + + public string description => "This is a demo event"; + + public async void Start(Discord.WebSocket.DiscordSocketClient client) + { + Console.WriteLine($"Hello World from {name}"); + + client.UserJoined += async (user) => { + await (await user.CreateDMChannelAsync()).SendMessageAsync("Welcome to server !"); + }; + } +} +``` + +#### Code description: +- name - The name of your event. It will appear in console when it loads +- description - The description of your event +- Start() - The main body of your event. This is executed when the bot loads all plugins + - client - the discord bot client +