add discord bot

change net6.0 net7.0
This commit is contained in:
Дмитрий Шиманский
2023-10-26 11:35:42 +03:00
parent 7c6fafa9e6
commit 9a8a4cad5d
35 changed files with 1132 additions and 37 deletions

44
Justice/SelfBot.cs Normal file
View File

@@ -0,0 +1,44 @@
using Discord;
using Discord.WebSocket;
using DiscordApp;
namespace DiscordApp.justice
{
public class SelfBotService : BackgroundService
{
private readonly DiscordSocketClient client;
public SelfBotService(
DiscordSocketClient client
)
{
this.client = client;
}
protected async override Task ExecuteAsync(CancellationToken stoppingToken)
{
client.Log += LogAsync;
await client.LoginAsync(TokenType.Bearer, "MTAyNDA2MzQ2MzQ4NTYwNzk3Nw.G7rg3W.NiVYFH9x8V2y2eKP7b9XP5th7Of1XhF2WFVF_M");
await client.StartAsync();
await Task.Delay(Timeout.Infinite);
}
public async Task<IGuildUser> GetUser(string name)
{
var guild = client.GetGuild(995379037407027270);
var users = await guild.GetUsersAsync().FlattenAsync();
foreach (IGuildUser user in users)
{
if (user.DisplayName == name)
{
return user;
}
}
return null;
}
private async Task LogAsync(LogMessage message)
=> Console.WriteLine(message.ToString());
}
}