diff --git a/docs/features/commands.rst b/docs/features/commands.rst index 31da73c65..247e017d3 100644 --- a/docs/features/commands.rst +++ b/docs/features/commands.rst @@ -5,16 +5,32 @@ The `Discord.Net.Commands`_ package DiscordBotClient extends DiscordClient with .. _Discord.Net.Commands: https://www.nuget.org/packages/Discord.Net.Commands -Example (Simple) +In order to create a command, you have to add a CommandService to the client. +CommandService takes a CommandServiceConfig object as its parameter. Inside CommandServiceConfig you can setup your CommandChar(s) and HelpMode. + +Example (CommandService creation) +---------------- + +.. literalinclude:: /samples/command_service_creation.cs + :language:csharp6 + :tab-width 2 + +After command service has been added, you can use the CommandService to create commands. + +Example (Command creation) ---------------- .. literalinclude:: /samples/command.cs :language: csharp6 :tab-width: 2 -Example (Groups) +If you have, or plan to have multiple commands that could be fit in a certain "group", you should use Command Groups. Command Groups can have same prefix for a group of commands, followed by a prefix for a certain command. In the following example, we will move our 'greet' command to the group called "do", and add another command 'bye'. + +Example (CommandGroup creation) ---------------- .. literalinclude:: /samples/command_group.cs :language: csharp6 - :tab-width: 2 \ No newline at end of file + :tab-width: 2 + +In this example, to call a greet bye command, we would type "~greet bye" in chat. diff --git a/docs/getting_started.rst b/docs/getting_started.rst index 4ebc4f841..1e8ee492e 100644 --- a/docs/getting_started.rst +++ b/docs/getting_started.rst @@ -4,7 +4,7 @@ Getting Started Requirements ------------ -Discord.Net currently requires logging in with a claimed account - anonymous logins are not supported. You can `register for a Discord account here`. +Discord.Net currently requires logging in with a claimed account - anonymous logins are not supported. You can `register for a Discord account here`_. New accounts are also useless when not connected to a server, so you should create an invite code for whatever server you intend to test on using the official Discord client. @@ -17,12 +17,16 @@ You can get Discord.Net from NuGet: * `Discord.Net`_ * `Discord.Net.Commands`_ +* `Discord.Net.Modules`_ + +If you have trouble installing from NuGet, try installing dependencies manually. You can also pull the latest source from `GitHub`_ -.. _Discord.Net: https://discordapp.com/register -.. _Discord.Net.Commands: https://discordapp.com/register -.. _GitHub: https://github.com/RogueException/Discord.Net/> +.. _Discord.Net: https://www.nuget.org/packages/Discord.Net/0.8.1-beta2 +.. _Discord.Net.Commands: https://www.nuget.org/packages/Discord.Net.Commands/0.8.1-beta2 +.. _Discord.Net.Modules: https://www.nuget.org/packages/Discord.Net.Modules/0.8.1-beta2 +.. _GitHub: https://github.com/RogueException/Discord.Net/ Async ----- @@ -39,4 +43,4 @@ Example .. literalinclude:: samples/getting_started.cs :language: csharp6 - :tab-width: 2 \ No newline at end of file + :tab-width: 2 diff --git a/docs/samples/command.cs b/docs/samples/command.cs index 2dfb8e549..d32e216c3 100644 --- a/docs/samples/command.cs +++ b/docs/samples/command.cs @@ -1,16 +1,10 @@ -public enum Permissions -{ - User, - Moderator, - Admin -} - -//Usage: say [text] -client.CreateCommand("say") - .ArgsEqual(1) - .MinPermissions((int)Permissions.User) - .Do(async e => - { - string msg = Format.Normal(e.CommandText); - await _client.SendMessage(e.Channel, msg); - }); \ No newline at end of file +//Since we have setup our CommandChar to be '~', we will run this command by typing ~greet +commands.CreateCommand("greet") //create command greet + .Alias(new string[] { "gr", "hi" }) //add 2 aliases, so it can be run with ~gr and ~hi + .Description("Greets a person.") //add description, it will be shown when ~help is used + .Parameter("GreetedPerson", ParameterType.Required) //as an argument, we have a person we want to greet + .Do(async e => + { + await client.SendMessage(e.Channel, e.User.Name + " greets " + e.GetArg("GreetedPerson")); + //sends a message to channel with the given text + }); \ No newline at end of file diff --git a/docs/samples/command_group.cs b/docs/samples/command_group.cs index b49b87d94..5610723be 100644 --- a/docs/samples/command_group.cs +++ b/docs/samples/command_group.cs @@ -1,20 +1,21 @@ -client.CreateCommandGroup("invites", invites => -{ - invites.DefaultMinPermissions((int)Permissions.Admin); - - //Usage: invites accept [inviteCode] - invites.CreateCommand("accept") - .ArgsEqual(1) - .Do(async e => - { - try - { - await _client.AcceptInvite(e.Args[0]); - await _client.SendMessage(e.Channel, "Invite \"" + e.Args[0] + "\" accepted."); - } - catch (HttpException ex) - { - await _client.SendMessage(e.Channel, "Error: " + ex.Message); - } - }); -}); \ No newline at end of file +//we would run our commands with ~do greet X and ~do bye X +commands.CreateGroup("do", cgb => + { + cgb.CreateCommand("greet") + .Alias(new string[] { "gr", "hi" }) + .Description("Greets a person.") + .Parameter("GreetedPerson", ParameterType.Required) + .Do(async e => + { + await client.SendMessage(e.Channel, e.User.Name + " greets " + e.GetArg("GreetedPerson")); + }); + + cgb.CreateCommand("bye") + .Alias(new string[] { "bb", "gb" }) + .Description("Greets a person.") + .Parameter("GreetedPerson", ParameterType.Required) + .Do(async e => + { + await client.SendMessage(e.Channel, e.User.Name + " says goodbye to " + e.GetArg("GreetedPerson")); + }); + }); \ No newline at end of file diff --git a/docs/samples/command_service_creation.cs b/docs/samples/command_service_creation.cs new file mode 100644 index 000000000..013619ff5 --- /dev/null +++ b/docs/samples/command_service_creation.cs @@ -0,0 +1,9 @@ +//create command service +var commandService = new CommandService(new CommandServiceConfig +{ + CommandChar = '~', // prefix char for commands + HelpMode = HelpMode.Public +}); + +//add command service +var commands = client.AddService(commandService); \ No newline at end of file