Coder Social home page Coder Social logo

carrotcord-discord-library's Introduction

Carrotcord-Discord-Library

A Discord library made by JohnyTheCarrot

WORK IN PROGRESS

This library is barely usable in it's current state.

HOW-TO

Creating your bot

The following will login and initialize your bot.

class Program
{

	public static void Main(string[] args)
		=> new Program().MainAsync().GetAwaiter().GetResult();
		
	public static Bot bot;
	private string token = "INSERT TOKEN HERE";
	
	public async Task MainAsync()
	{
		bot = new Bot(token);
		await Task.Delay(-1);
	}

}

Creating your first commands

Now that we have our bot set up, we'd like to add some commands. Let's make the classic ping pong command.

class Program
{

	public static void Main(string[] args)
		=> new Program().MainAsync().GetAwaiter().GetResult();
		
	public static Bot bot;
	private string token = "INSERT TOKEN HERE";
	
	public async Task MainAsync()
	{
		bot = new Bot(token);
		
		//NEW
		bot.RegisterCommand(new Command("ping", new Action<CommandContext>(context => {
			context.message.reply("pong");
		})));
		//NEW
		
		await Task.Delay(-1);
	}

}

DOCS

Commands

ARGUMENTS

            Bot bot = new Bot(token);
            bot.RegisterCommand(new Command("argtest", new Action<CommandContext>(context =>
            {
                string args = "";
                foreach(string arg in context.args)
                {
                    args += arg + "\n";
                }
                DiscordEmbed embed = new DiscordEmbed()
                {
                    title = "arguments",
                    description = args
                };
                context.message.reply("", embed);
            }))
            {
                minArgs = 1, //minimum arguments required for the command
                maxArgs = 4, //maximum arguments allowed in the command
                //when the command gets canceled because of whatever reason, the following will fire
                //when the argument count is less than minArgs or greater than maxArgs, it will also cancel the command and fire the following
                onCommandCanceled = new Action<string, CommandContext>((reason, context) => {
                    context.message.reply(reason);
                })
            });

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.