C# Discord Bot

簡單記錄一下 DC 私聊機器人

Rider

結論

using Discord;
using Discord.WebSocket;

var client = new DiscordSocketClient();

client.Log += (message) =>
{
    Console.WriteLine(message);
    return Task.CompletedTask;
};

client.Ready += () =>
{
    Console.WriteLine("Bot is ready!");
    return Task.CompletedTask;
};

client.MessageReceived += async (message) =>
{
    Console.WriteLine(message);
    // Ignore messages sent by the bot itself
    if (message.Author.Id == client.CurrentUser.Id)
        return;

    // Respond to messages that contain "hello"
    if (message.Content.Contains("hello"))
    {
        await message.Channel.SendMessageAsync("Hi there!");
    }
};

await client.LoginAsync(TokenType.Bot, "YourTokenXxxxxxxx");
await client.StartAsync();
await Task.Delay(-1);
PS5