Browse Source

Modify module samples to use SocketCommandContext instead

pull/826/head
Hsu Still 8 years ago
parent
commit
caa5b15e53
2 changed files with 6 additions and 10 deletions
  1. +1
    -1
      docs/guides/commands/samples/empty-module.cs
  2. +5
    -9
      docs/guides/commands/samples/module.cs

+ 1
- 1
docs/guides/commands/samples/empty-module.cs View File

@@ -1,6 +1,6 @@
using Discord.Commands; using Discord.Commands;


public class InfoModule : ModuleBase
public class InfoModule : ModuleBase<SocketCommandContext>
{ {
} }

+ 5
- 9
docs/guides/commands/samples/module.cs View File

@@ -1,13 +1,9 @@
using Discord;
using Discord.Commands;
using Discord.WebSocket;

// Create a module with no prefix // Create a module with no prefix
public class Info : ModuleBase
public class Info : ModuleBase<SocketCommandContext>
{ {
// ~say hello -> hello // ~say hello -> hello
[Command("say"), Summary("Echos a message.")] [Command("say"), Summary("Echos a message.")]
public async Task Say([Remainder, Summary("The text to echo")] string echo)
public async Task SayAsync([Remainder, Summary("The text to echo")] string echo)
{ {
// ReplyAsync is a method on ModuleBase // ReplyAsync is a method on ModuleBase
await ReplyAsync(echo); await ReplyAsync(echo);
@@ -16,11 +12,11 @@ public class Info : ModuleBase


// Create a module with the 'sample' prefix // Create a module with the 'sample' prefix
[Group("sample")] [Group("sample")]
public class Sample : ModuleBase
public class Sample : ModuleBase<SocketCommandContext>
{ {
// ~sample square 20 -> 400 // ~sample square 20 -> 400
[Command("square"), Summary("Squares a number.")] [Command("square"), Summary("Squares a number.")]
public async Task Square([Summary("The number to square.")] int num)
public async Task SquareAsync([Summary("The number to square.")] int num)
{ {
// We can also access the channel from the Command Context. // We can also access the channel from the Command Context.
await Context.Channel.SendMessageAsync($"{num}^2 = {Math.Pow(num, 2)}"); await Context.Channel.SendMessageAsync($"{num}^2 = {Math.Pow(num, 2)}");
@@ -34,7 +30,7 @@ public class Sample : ModuleBase
// ~sample whois 96642168176807936 --> Khionu#8708 // ~sample whois 96642168176807936 --> Khionu#8708
[Command("userinfo"), Summary("Returns info about the current user, or the user parameter, if one passed.")] [Command("userinfo"), Summary("Returns info about the current user, or the user parameter, if one passed.")]
[Alias("user", "whois")] [Alias("user", "whois")]
public async Task UserInfo([Summary("The (optional) user to get info for")] IUser user = null)
public async Task UserInfoAsync([Summary("The (optional) user to get info for")] SocketUser user = null)
{ {
var userInfo = user ?? Context.Client.CurrentUser; var userInfo = user ?? Context.Client.CurrentUser;
await ReplyAsync($"{userInfo.Username}#{userInfo.Discriminator}"); await ReplyAsync($"{userInfo.Username}#{userInfo.Discriminator}");


Loading…
Cancel
Save