Browse Source

Add check for bot messages.

Added a check so bot messages do not trigger any commands involuntariy.
tags/2.0
Rithari Monica S 6 years ago
parent
commit
f3b9f35899
1 changed files with 4 additions and 3 deletions
  1. +4
    -3
      docs/guides/commands/samples/intro/command_handler.cs

+ 4
- 3
docs/guides/commands/samples/intro/command_handler.cs View File

@@ -35,9 +35,10 @@ public class CommandHandler
// Create a number to track where the prefix ends and the command begins
int argPos = 0;

// Determine if the message is a command based on the prefix
// Determine if the message is a command based on the prefix and make sure no bots trigger commands
if (!(message.HasCharPrefix('!', ref argPos) ||
message.HasMentionPrefix(_client.CurrentUser, ref argPos)))
message.HasMentionPrefix(_client.CurrentUser, ref argPos)) ||
message.Author.IsBot)
return;

// Create a WebSocket-based command context based on the message
@@ -60,4 +61,4 @@ public class CommandHandler
// if (!result.IsSuccess)
// await context.Channel.SendMessageAsync(result.ErrorReason);
}
}
}

Loading…
Cancel
Save