| @@ -4,7 +4,7 @@ Getting Started | |||||
| Requirements | 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. | 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`_ | ||||
| * `Discord.Net.Commands`_ | * `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`_ | 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 | Async | ||||
| ----- | ----- | ||||
| @@ -39,4 +43,4 @@ Example | |||||
| .. literalinclude:: samples/getting_started.cs | .. literalinclude:: samples/getting_started.cs | ||||
| :language: csharp6 | :language: csharp6 | ||||
| :tab-width: 2 | |||||
| :tab-width: 2 | |||||
| @@ -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); | |||||
| }); | |||||
| //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 | |||||
| }); | |||||
| @@ -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); | |||||
| } | |||||
| }); | |||||
| }); | |||||
| //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")); | |||||
| }); | |||||
| }); | |||||
| @@ -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); | |||||