Browse Source

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
pull/1304/head
Still Hsu 6 years ago
parent
commit
610c6974bc
2 changed files with 10 additions and 66 deletions
  1. +10
    -56
      docs/guides/getting_started/first-bot.md
  2. +0
    -10
      docs/guides/getting_started/samples/first-bot/complete.cs

+ 10
- 56
docs/guides/getting_started/first-bot.md View File

@@ -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 At this point, feel free to start your program and see your bot come
online in Discord. online in Discord.


> [!TIP]
> [!WARNING]
> Getting a warning about `A supplied token was invalid.` and/or > Getting a warning about `A supplied token was invalid.` and/or
> having trouble logging in? Double-check whether you have put in > having trouble logging in? Double-check whether you have put in
> the correct credentials and make sure that it is _not_ a client > the correct credentials and make sure that it is _not_ a client
> secret, which is different from a token. > secret, which is different from a token.


> [!TIP]
> [!WARNING]
> Encountering a `PlatformNotSupportedException` when starting your bot? > Encountering a `PlatformNotSupportedException` when starting your bot?
> This means that you are targeting a platform where .NET's default > This means that you are targeting a platform where .NET's default
> WebSocket client is not supported. Refer to the [installation guide] > WebSocket client is not supported. Refer to the [installation guide]
> for how to fix this. > for how to fix this.


> [!NOTE]
> For your reference, you may view the [completed program].

[DiscordSocketClient]: xref:Discord.WebSocket.DiscordSocketClient [DiscordSocketClient]: xref:Discord.WebSocket.DiscordSocketClient
[LoginAsync]: xref:Discord.Rest.BaseDiscordClient.LoginAsync* [LoginAsync]: xref:Discord.Rest.BaseDiscordClient.LoginAsync*
[StartAsync]: xref:Discord.WebSocket.DiscordSocketClient.StartAsync* [StartAsync]: xref:Discord.WebSocket.DiscordSocketClient.StartAsync*
[installation guide]: xref:Guides.GettingStarted.Installation [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 [completed program]: samples/first-bot/complete.cs


# Building a bot with commands # 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. For reference, view an [annotated example] of this structure.




+ 0
- 10
docs/guides/getting_started/samples/first-bot/complete.cs View File

@@ -9,7 +9,6 @@ public class Program
{ {
_client = new DiscordSocketClient(); _client = new DiscordSocketClient();
_client.Log += Log; _client.Log += Log;
_client.MessageReceived += MessageReceivedAsync;
await _client.LoginAsync(TokenType.Bot, await _client.LoginAsync(TokenType.Bot,
Environment.GetEnvironmentVariable("DiscordToken")); Environment.GetEnvironmentVariable("DiscordToken"));
await _client.StartAsync(); await _client.StartAsync();
@@ -17,15 +16,6 @@ public class Program
// Block this task until the program is closed. // Block this task until the program is closed.
await Task.Delay(-1); await Task.Delay(-1);
} }

private async Task MessageReceivedAsync(SocketMessage message)
{
if (message.Content == "!ping")
{
await message.Channel.SendMessageAsync("Pong!");
}
}

private Task Log(LogMessage msg) private Task Log(LogMessage msg)
{ {
Console.WriteLine(msg.ToString()); Console.WriteLine(msg.ToString());


Loading…
Cancel
Save