From 11282090537b5356cd30682d7eab36274e557b9a Mon Sep 17 00:00:00 2001 From: Patryk R Date: Wed, 5 Sep 2018 20:52:53 +0100 Subject: [PATCH 1/3] Added commands to sample bot --- .../Modules/PublicModule.cs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/samples/02_commands_framework/Modules/PublicModule.cs b/samples/02_commands_framework/Modules/PublicModule.cs index f30dfd73f..2bb15dd4a 100644 --- a/samples/02_commands_framework/Modules/PublicModule.cs +++ b/samples/02_commands_framework/Modules/PublicModule.cs @@ -49,6 +49,32 @@ namespace _02_commands_framework.Modules await ReplyAsync("ok!"); } + // Unban a user + [Command("unban")] + [RequireContext(ContextType.Guild)] + // make sure the user invoking the coomand can unban + [RequireUserPermission(GuildPermission.BanMembers)] + // make sure the bot itself can unban + [RequireBotPermission(GuildPermission.BanMembers)] + public async Task UnbanUserAsync(IGuildUser user) + { + await user.Guild.RemoveBanAsync(user); + await ReplyAsync("ok!"); + } + + // Kick a user + [Command("kick")] + [RequireContext(ContextType.Guild)] + // make sure the user invoking the coomand can kick + [RequireUserPermission(GuildPermission.KickMembers)] + // make sure the bot itself can kick + [RequireBotPermission(GuildPermission.KickMembers)] + public async Task KickUserAsync(IGuildUser user, [Remainder] string reason = null) + { + await user.KickAsync(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) @@ -59,5 +85,18 @@ namespace _02_commands_framework.Modules [Command("list")] public Task ListAsync(params string[] objects) => ReplyAsync("You listed: " + string.Join("; ", objects)); + + // Can be used to example put information + [Command("info")] + public async Task InformationAsync() + { + // Creates the pattern TextBlock + EmbedBuilder builder = new EmbedBuilder(); + //builder.AddField("title", ""); + builder.WithTitle("This is Discord!") + .WithColor(Color.Orange); + + await ReplyAsync("", false, builder.Build()); + } } } From 10bfccd97cc5c12bfc2a39140bf321233e1579cb Mon Sep 17 00:00:00 2001 From: Patryk R Date: Wed, 5 Sep 2018 21:53:51 +0100 Subject: [PATCH 2/3] Fixed problems with used command with reason. --- .../02_commands_framework/Modules/PublicModule.cs | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/samples/02_commands_framework/Modules/PublicModule.cs b/samples/02_commands_framework/Modules/PublicModule.cs index 2bb15dd4a..0b2379d15 100644 --- a/samples/02_commands_framework/Modules/PublicModule.cs +++ b/samples/02_commands_framework/Modules/PublicModule.cs @@ -49,19 +49,6 @@ namespace _02_commands_framework.Modules await ReplyAsync("ok!"); } - // Unban a user - [Command("unban")] - [RequireContext(ContextType.Guild)] - // make sure the user invoking the coomand can unban - [RequireUserPermission(GuildPermission.BanMembers)] - // make sure the bot itself can unban - [RequireBotPermission(GuildPermission.BanMembers)] - public async Task UnbanUserAsync(IGuildUser user) - { - await user.Guild.RemoveBanAsync(user); - await ReplyAsync("ok!"); - } - // Kick a user [Command("kick")] [RequireContext(ContextType.Guild)] @@ -71,7 +58,7 @@ namespace _02_commands_framework.Modules [RequireBotPermission(GuildPermission.KickMembers)] public async Task KickUserAsync(IGuildUser user, [Remainder] string reason = null) { - await user.KickAsync(reason); + await user.KickAsync(reason, null); await ReplyAsync("ok!"); } From 9ce0c3938a2b9a3a8ba6d16290532352f9e6e428 Mon Sep 17 00:00:00 2001 From: Patryk R Date: Wed, 5 Sep 2018 22:25:58 +0100 Subject: [PATCH 3/3] Removed info command and EmbedBuilder created in kick. --- .../Modules/PublicModule.cs | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/samples/02_commands_framework/Modules/PublicModule.cs b/samples/02_commands_framework/Modules/PublicModule.cs index 0b2379d15..542dbfd25 100644 --- a/samples/02_commands_framework/Modules/PublicModule.cs +++ b/samples/02_commands_framework/Modules/PublicModule.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using Discord; using Discord.Commands; using _02_commands_framework.Services; +using System; namespace _02_commands_framework.Modules { @@ -52,14 +53,24 @@ namespace _02_commands_framework.Modules // Kick a user [Command("kick")] [RequireContext(ContextType.Guild)] - // make sure the user invoking the coomand can kick + // make sure the user invoking the command can kick [RequireUserPermission(GuildPermission.KickMembers)] // make sure the bot itself can kick [RequireBotPermission(GuildPermission.KickMembers)] public async Task KickUserAsync(IGuildUser user, [Remainder] string reason = null) { + // Creates the pattern TextBlock + EmbedBuilder builder = new EmbedBuilder(); + + builder.WithTitle(user.Username + " kicked from server!") + .WithColor(Color.Orange) + .WithDescription("by " + + $"{Context.User.Username}" + + Environment.NewLine + + "Reason: " + reason); + await user.KickAsync(reason, null); - await ReplyAsync("ok!"); + await ReplyAsync("", false, builder.Build()); } // [Remainder] takes the rest of the command's arguments as one argument, rather than splitting every space @@ -72,18 +83,5 @@ namespace _02_commands_framework.Modules [Command("list")] public Task ListAsync(params string[] objects) => ReplyAsync("You listed: " + string.Join("; ", objects)); - - // Can be used to example put information - [Command("info")] - public async Task InformationAsync() - { - // Creates the pattern TextBlock - EmbedBuilder builder = new EmbedBuilder(); - //builder.AddField("title", ""); - builder.WithTitle("This is Discord!") - .WithColor(Color.Orange); - - await ReplyAsync("", false, builder.Build()); - } } }