MeDsCore is an async Discord Bot API library. me.ds
module uses this library to interact with Discord
- Create a Service Worker project template
- Add in your
appsettings.json
the following JSON property
"DsToken": "<YOUR_BEAUTIFUL_TOKEN>"
- Replace code in the
Program.cs
by this
using MeDsCore;
using MeDsCore.WebSocket.Gateway;
IHost host = Host.CreateDefaultBuilder(args)
.ConfigureLogging(x =>
{
x.ClearProviders();
x.AddMeDsBotLogger();
x.SetMinimumLevel(LogLevel.Trace);
})
.ConfigureServices((context, services) =>
{
services.AddHostedService<BotWorker>()
.AddSingleton<DiscordClient>()
.AddSingleton(new DiscordClientConfiguration(context.Configuration["DsToken"])
{
Intents = GatewayIntents.GuildsIntent |
GatewayIntents.GuildPresencesIntent |
GatewayIntents.GuildMessagesIntent
});
})
.Build();
await host.RunAsync();
- Create a class named
BotWorker
using System.Reflection;
using MeDsCore;
namespace MeDsBot.Workers;
public class BotWorker : BackgroundService
{
private readonly DiscordClient _discordClient;
public BotWorker(DiscordClient discordClient)
{
_discordClient = discordClient;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
await _discordClient.StartAsync();
await Task.Delay(-1, stoppingToken);
}
}
Result: