-
Notifications
You must be signed in to change notification settings - Fork 0
/
DiscordBot.cs
46 lines (36 loc) · 1.21 KB
/
DiscordBot.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
using Discord;
using Discord.WebSocket;
namespace TelegramBuildBot;
public class DiscordBot
{
private readonly DiscordSocketClient _client;
public DiscordBot()
{
var settings = new DiscordSocketConfig();
settings.GatewayIntents = GatewayIntents.AllUnprivileged | GatewayIntents.MessageContent;
_client = new DiscordSocketClient(settings);
_client.Log += LogAsync;
_client.MessageReceived += MessageReceivedAsync;
}
private Task LogAsync(LogMessage log)
{
Console.WriteLine($"DISCORD: {log.ToString()}");
return Task.CompletedTask;
}
private async Task MessageReceivedAsync(SocketMessage message)
{
if (message.Author.Id == _client.CurrentUser.Id || message.Author.IsBot)
return;
Console.WriteLine($"DISCORDMSG: {message.Content}");
string? responseMsg = await Program.Builder.ProcessMessage(message.Content);
if (responseMsg != null)
{
await message.Channel.SendMessageAsync(responseMsg);
}
}
public async Task StartBot(string token)
{
await _client.LoginAsync(TokenType.Bot, token);
await _client.StartAsync();
}
}