Browse Source

Fix missing attributes, show use of preconditions

pull/972/head
Christopher F 8 years ago
parent
commit
b4c380ab87
2 changed files with 15 additions and 1 deletions
  1. +14
    -0
      samples/02_commands_framework/Modules/PublicModule.cs
  2. +1
    -1
      samples/02_commands_framework/Program.cs

+ 14
- 0
samples/02_commands_framework/Modules/PublicModule.cs View File

@@ -36,6 +36,19 @@ namespace _02_commands_framework.Modules
await ReplyAsync(user.ToString());
}

// Ban a user
[Command("ban")]
[RequireContext(ContextType.Guild)]
// make sure the user invoking the command can ban
[RequireUserPermission(GuildPermission.BanMembers)]
// make sure the bot itself can ban
[RequireBotPermission(GuildPermission.BanMembers)]
public async Task BanUserAsync(IGuildUser user, [Remainder] string reason = null)
{
await user.Guild.AddBanAsync(user, reason: reason);
await ReplyAsync("ok!");
}

// [Remainder] takes the rest of the command's arguments as one argument, rather than splitting every space
[Command("echo")]
public Task EchoAsync([Remainder] string text)
@@ -43,6 +56,7 @@ namespace _02_commands_framework.Modules
=> ReplyAsync('\u200B' + text);

// 'params' will parse space-separated elements into a list
[Command("list")]
public Task ListAsync(params string[] objects)
=> ReplyAsync("You listed: " + string.Join("; ", objects));
}


+ 1
- 1
samples/02_commands_framework/Program.cs View File

@@ -1,11 +1,11 @@
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Discord;
using Discord.WebSocket;
using Discord.Commands;
using _02_commands_framework.Services;
using System.Net.Http;

namespace _02_commands_framework
{


Loading…
Cancel
Save