From 610c6974bc70652fb32d6e4ef5a886aca168e715 Mon Sep 17 00:00:00 2001 From: Still Hsu <341464@gmail.com> Date: Sat, 16 Feb 2019 11:32:07 +0800 Subject: [PATCH] Remove misleading section about commands - Remove command sample from complete snippet * Revise "Your First Bot" command paragraphs * Change wording to hint devs that additional command parser packages may be available, as more and more begin to crop up --- docs/guides/getting_started/first-bot.md | 66 +++---------------- .../samples/first-bot/complete.cs | 10 --- 2 files changed, 10 insertions(+), 66 deletions(-) diff --git a/docs/guides/getting_started/first-bot.md b/docs/guides/getting_started/first-bot.md index 6f71a605b..eb140cd75 100644 --- a/docs/guides/getting_started/first-bot.md +++ b/docs/guides/getting_started/first-bot.md @@ -182,80 +182,34 @@ The following lines can now be added: At this point, feel free to start your program and see your bot come online in Discord. -> [!TIP] +> [!WARNING] > Getting a warning about `A supplied token was invalid.` and/or > having trouble logging in? Double-check whether you have put in > the correct credentials and make sure that it is _not_ a client > secret, which is different from a token. -> [!TIP] +> [!WARNING] > Encountering a `PlatformNotSupportedException` when starting your bot? > This means that you are targeting a platform where .NET's default > WebSocket client is not supported. Refer to the [installation guide] > for how to fix this. +> [!NOTE] +> For your reference, you may view the [completed program]. + [DiscordSocketClient]: xref:Discord.WebSocket.DiscordSocketClient [LoginAsync]: xref:Discord.Rest.BaseDiscordClient.LoginAsync* [StartAsync]: xref:Discord.WebSocket.DiscordSocketClient.StartAsync* [installation guide]: xref:Guides.GettingStarted.Installation - -### Handling a 'ping' - -> [!WARNING] -> Please note that this is *not* a proper way to create a command. -> -> Consider using a command framework instead. One is provided to you -> in `Discord.Net.Commands`; see @Guides.Commands.Intro for more -> information. - -Now that we have learned to open a connection to Discord, we can -begin handling messages that the users are sending. - -To start out, our bot will listen for any message whose content -is equal to `!ping` and will respond back with "Pong!". Since we want -to listen for new messages, the event to hook into is [MessageReceived]. - -In your program, add a method that matches the signature of the -`MessageReceived` event - it must be a method (`Func`) that returns -the type `Task` and takes a single parameter, a [SocketMessage]. Also, -since we will be sending data to Discord in this method, we will flag -it as `async`. -In this method, we will add an `if` block to -determine if the message content fits the rules of our scenario - -recall that it must be equal to `!ping`. -Inside the branch of this condition, we will want to send a message, -`Pong!`, back to the channel from which the message comes from. To -find the channel, look for the `Channel` property on the message -parameter. - -Next, we will want to send a message to this channel. Since the -channel object is of type [ISocketMessageChannel], we can invoke the -[SendMessageAsync] instance method. For the message content, send back -a string, "Pong!". - -You should have now added the following lines, - -[!code-csharp[Message](samples/first-bot/message.cs)] - -Now that your first bot is complete. You may continue to add on to this -if you desire, but for any bots that will be carrying out multiple -commands, it is strongly recommended to use the command framework as -shown below. - -> [!NOTE] -> For your reference, you may view the [completed program]. - -[MessageReceived]: xref:Discord.WebSocket.BaseSocketClient.MessageReceived -[SocketMessage]: xref:Discord.WebSocket.SocketMessage -[ISocketMessageChannel]: xref:Discord.WebSocket.ISocketMessageChannel -[SendMessageAsync]: xref:Discord.WebSocket.ISocketMessageChannel.SendMessageAsync* [completed program]: samples/first-bot/complete.cs # Building a bot with commands -@Guides.Commands.Intro will guide you through how to setup a program -that is ready for [CommandService], a service that is ready for -advanced command usage. +To create commands for your bot, you may choose from a variety of +command processors available. Throughout the guides, we will be using +the one that Discord.Net ships with. @Guides.Commands.Intro will +guide you through how to setup a program that is ready for +[CommandService]. For reference, view an [annotated example] of this structure. diff --git a/docs/guides/getting_started/samples/first-bot/complete.cs b/docs/guides/getting_started/samples/first-bot/complete.cs index 3a7cb061d..871641e23 100644 --- a/docs/guides/getting_started/samples/first-bot/complete.cs +++ b/docs/guides/getting_started/samples/first-bot/complete.cs @@ -9,7 +9,6 @@ public class Program { _client = new DiscordSocketClient(); _client.Log += Log; - _client.MessageReceived += MessageReceivedAsync; await _client.LoginAsync(TokenType.Bot, Environment.GetEnvironmentVariable("DiscordToken")); await _client.StartAsync(); @@ -17,15 +16,6 @@ public class Program // Block this task until the program is closed. await Task.Delay(-1); } - - private async Task MessageReceivedAsync(SocketMessage message) - { - if (message.Content == "!ping") - { - await message.Channel.SendMessageAsync("Pong!"); - } - } - private Task Log(LogMessage msg) { Console.WriteLine(msg.ToString());