-
Notifications
You must be signed in to change notification settings - Fork 0
/
RecieveMessage.cs
45 lines (36 loc) · 1.14 KB
/
RecieveMessage.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
using Discord;
using Discord.WebSocket;
using System.Diagnostics;
namespace FlowDiscord
{
internal class RecieveMessage
{
private static DiscordSocketClient _client;
public async Task StartAsync()
{
var socketConfig = new DiscordSocketConfig
{
GatewayIntents = GatewayIntents.AllUnprivileged | GatewayIntents.MessageContent,
};
_client = new DiscordSocketClient(socketConfig);
var token = "BOT TOKEN";
await _client.LoginAsync(TokenType.Bot, token);
await _client.StartAsync();
_client.MessageReceived += MessageReceived;
_client.Ready += () =>
{
MainWindow.CreateNewMessage("Discordに接続しました");
return Task.CompletedTask;
};
await Task.Delay(-1);
}
private static Task MessageReceived(SocketMessage message)
{
if (message != null)
{
MainWindow.CreateNewMessage(message.Content);
}
return Task.CompletedTask;
}
}
}