@@ -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: https://www.nuget.org/packages/Discord.Net/0.8.1-beta2
|
||||||
.. _Discord.Net.Commands: https://discordapp.com/register
|
.. _Discord.Net.Commands: https://www.nuget.org/packages/Discord.Net.Commands/0.8.1-beta2
|
||||||
.. _GitHub: https://github.com/RogueException/Discord.Net/>
|
.. _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
|
//Since we have setup our CommandChar to be '~', we will run this command by typing ~greet
|
||||||
{
|
commands.CreateCommand("greet") //create command greet
|
||||||
User,
|
.Alias(new string[] { "gr", "hi" }) //add 2 aliases, so it can be run with ~gr and ~hi
|
||||||
Moderator,
|
.Description("Greets a person.") //add description, it will be shown when ~help is used
|
||||||
Admin
|
.Parameter("GreetedPerson", ParameterType.Required) //as an argument, we have a person we want to greet
|
||||||
}
|
.Do(async e =>
|
||||||
|
{
|
||||||
//Usage: say [text]
|
await client.SendMessage(e.Channel, e.User.Name + " greets " + e.GetArg("GreetedPerson"));
|
||||||
client.CreateCommand("say")
|
//sends a message to channel with the given text
|
||||||
.ArgsEqual(1)
|
});
|
||||||
.MinPermissions((int)Permissions.User)
|
|
||||||
.Do(async e =>
|
|
||||||
{
|
|
||||||
string msg = Format.Normal(e.CommandText);
|
|
||||||
await _client.SendMessage(e.Channel, msg);
|
|
||||||
});
|
|
||||||
@@ -1,20 +1,21 @@
|
|||||||
client.CreateCommandGroup("invites", invites =>
|
//we would run our commands with ~do greet X and ~do bye X
|
||||||
{
|
commands.CreateGroup("do", cgb =>
|
||||||
invites.DefaultMinPermissions((int)Permissions.Admin);
|
{
|
||||||
|
cgb.CreateCommand("greet")
|
||||||
//Usage: invites accept [inviteCode]
|
.Alias(new string[] { "gr", "hi" })
|
||||||
invites.CreateCommand("accept")
|
.Description("Greets a person.")
|
||||||
.ArgsEqual(1)
|
.Parameter("GreetedPerson", ParameterType.Required)
|
||||||
.Do(async e =>
|
.Do(async e =>
|
||||||
{
|
{
|
||||||
try
|
await client.SendMessage(e.Channel, e.User.Name + " greets " + e.GetArg("GreetedPerson"));
|
||||||
{
|
});
|
||||||
await _client.AcceptInvite(e.Args[0]);
|
|
||||||
await _client.SendMessage(e.Channel, "Invite \"" + e.Args[0] + "\" accepted.");
|
cgb.CreateCommand("bye")
|
||||||
}
|
.Alias(new string[] { "bb", "gb" })
|
||||||
catch (HttpException ex)
|
.Description("Greets a person.")
|
||||||
{
|
.Parameter("GreetedPerson", ParameterType.Required)
|
||||||
await _client.SendMessage(e.Channel, "Error: " + ex.Message);
|
.Do(async e =>
|
||||||
}
|
{
|
||||||
});
|
await client.SendMessage(e.Channel, e.User.Name + " says goodbye to " + e.GetArg("GreetedPerson"));
|
||||||
});
|
});
|
||||||
|
});
|
||||||
9
docs/samples/command_service_creation.cs
Normal file
9
docs/samples/command_service_creation.cs
Normal file
@@ -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);
|
||||||
Reference in New Issue
Block a user