-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathSampleModule.cs
More file actions
75 lines (69 loc) · 3.2 KB
/
SampleModule.cs
File metadata and controls
75 lines (69 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using Discord;
using Discord.Addons.Interactive;
using Discord.Commands;
using System;
using System.Threading.Tasks;
namespace SampleApp.Modules
{
public class SampleModule : InteractiveBase
{
// DeleteAfterAsync will send a message and asynchronously delete it after the timeout has popped
// This method will not block.
[Command("delete")]
public async Task<RuntimeResult> Test_DeleteAfterAsync()
{
await ReplyAndDeleteAsync("this message will delete in 10 seconds", timeout: TimeSpan.FromSeconds(10));
return Ok();
}
// NextMessageAsync will wait for the next message to come in over the gateway, given certain criteria
// By default, this will be limited to messages from the source user in the source channel
// This method will block the gateway, so it should be ran in async mode.
[Command("next", RunMode = RunMode.Async)]
public async Task Test_NextMessageAsync()
{
await ReplyAsync("What is 2+2?");
var response = await NextMessageAsync();
if (response != null)
await ReplyAsync($"You replied: {response.Content}");
else
await ReplyAsync("You did not reply before the timeout");
}
// PagedReplyAsync will send a paginated message to the channel
// You can customize the paginator by creating a PaginatedMessage object
// You can customize the criteria for the paginator as well, which defaults to restricting to the source user
// This method will not block.
[Command("paginator")]
public async Task Test_Paginator()
{
var pages = new[] { "Page 1", "Page 2", "Page 3", "aaaaaa", "Page 5" };
await PagedReplyAsync(pages);
}
// InlineReactionReplyAsync will send a message and adds reactions on it.
// Once an user adds a reaction, the callback is fired.
// If callback was successfull next callback is not handled (message is unsubscribed).
// Unsuccessful callback is a reaction that did not have a callback.
[Command("reaction")]
public async Task Test_ReactionReply()
{
await InlineReactionReplyAsync(new ReactionCallbackData("text")
.WithCallback(new Emoji("👍"), c => c.Channel.SendMessageAsync("You've replied with 👍"))
.WithCallback(new Emoji("👎"), c => c.Channel.SendMessageAsync("You've replied with 👎"))
);
}
[Command("embedreaction")]
public async Task Test_EmedReactionReply()
{
var one = new Emoji("1⃣");
var two = new Emoji("2⃣");
var embed = new EmbedBuilder()
.WithTitle("Choose one")
.AddInlineField(one.Name, "Beer")
.AddInlineField(two.Name, "Drink")
.Build();
await InlineReactionReplyAsync(new ReactionCallbackData("text", embed)
.WithCallback(one, c => c.Channel.SendMessageAsync("Here you go :beer:"))
.WithCallback(two, c => c.Channel.SendMessageAsync("Here you go :tropical_drink:"))
);
}
}
}