-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
105 lines (95 loc) · 3.67 KB
/
Program.cs
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
using System.Threading.Tasks;
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.Entities;
using System.Data.SQLite;
using System.Collections.Generic;
namespace DiscordBot
{
internal class Program
{
static SQLiteHelper db = new SQLiteHelper();
static SQLiteCommand cmd;
static void Main(string[] args)
{
GoodClearBot goodClearBot = new GoodClearBot();
try
{
MainAsync().GetAwaiter().GetResult();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
static async Task MainAsync()
{
//随机数
Random ran = new Random();
//Discord Bot 连接Token
var discord = new DiscordClient(new DiscordConfiguration()
{
Token = DiscordToken.Token,
TokenType = TokenType.Bot,
Intents = DiscordIntents.AllUnprivileged
});;
var commands = discord.UseCommandsNext(new CommandsNextConfiguration()
{
StringPrefixes = new[] { "!" }
});
discord.MessageCreated += async (sender, e) =>
{
//Ping
if(e.Message.Content.ToLower() == "ping")
{
await e.Message.RespondAsync("Pong!");
};
//显示时间
if (e.Message.Content.ToLower() == "time")
{
await e.Message.RespondAsync("当前时间为" + System.DateTime.Now.ToString("F"));
};
//随机数
if (e.Message.Content.ToLower() == "random")
{
await e.Message.RespondAsync("数字为:" + ran.Next(100));
};
if (e.Message.Content.ToLower() == "list")
{
var options = new List<DiscordSelectComponentOption>()
{
new DiscordSelectComponentOption(
"标签1",
"label_no_desc"),
new DiscordSelectComponentOption(
"带备注的标签",
"label_with_desc",
"这是备注!"),
new DiscordSelectComponentOption(
"带备注和表情的标签",
"label_with_desc_emoji",
"这也是备注!",
emoji: new DiscordComponentEmoji(854260064906117121)),
new DiscordSelectComponentOption(
"带备注,表情的默认选中的标签",
"label_with_desc_emoji_default",
"我是默认选中的!",
isDefault: true,
new DiscordComponentEmoji(854260064906117121))
};
// Make the dropdown
var dropdown = new DiscordSelectComponent("dropdown", null, options, false, 1, 2);
var builder = new DiscordMessageBuilder()
.WithContent("我会在标签前发出来")
.AddComponents(dropdown);
await builder.SendAsync(e.Message.Channel);
};
};
//开启连接
commands.RegisterCommands<Command>();
await discord.ConnectAsync();
await Task.Delay(-1);
}
}
}