TheDarkun / Elevators

Fullstack .NET Project for SOČ
0 stars 0 forks source link

Create Discord Bot #20

Open TheDarkun opened 8 months ago

TheDarkun commented 8 months ago

Create Discord Bot

Objective

This issue is dedicated to creating the base Discord bot for our project. We will use the .NET Wrapper DSharp+ for as simple as possible development. Essential information such as the bot's token will be securely stored in secrets.json.

Implementation

Here is a code snippet of a basic bot with a ping-pong functionality to see if the bot is responding:

var discord = new DiscordClient(new DiscordConfiguration()
{
    Token = "My First Token",
    TokenType = TokenType.Bot,
    Intents = DiscordIntents.AllUnprivileged | DiscordIntents.MessageContents
});

discord.MessageCreated += async (s, e) =>
{
    if (e.Message.Content.ToLower().StartsWith("ping"))
        await e.Message.RespondAsync("pong!");
};

await discord.ConnectAsync();

For more info, check out the docs here