/DiscordNETWorkshop

Discord.NET workshop for Kennisweekend

Primary LanguageC#

DiscordNETWorkshop

Discord.NET workshop for Kennisweekend

Get started

All steps are also described here with images: https://docs.discordnet.dev/guides/getting_started/first-bot.html

  1. Create a Discord account

  2. Install the Discord.Net package in your solution (done already in project)

  3. Create a bot on: https://discord.com/developers/applications/

    1. Click "New Application"
    2. Fill in the details and click save
    3. Go to the "Bot" tab on the left and Click "Add Bot" if needed
    4. Click Reset Token if you didn't get a token yet and copy and store it somewhere (for this project in the user secrets, by right clicking the project => "Manage User Secrets")
    5. Go to the "Privileged Gateway Intents" and check the last one "MESSAGE CONTENT INTENT", so our bot can read server messages.
  4. Add your bot to a server

    1. Go to "OAuth2" tab
    2. Scroll down to OAuth2 URL Generator and under Scopes tick bot and applications.commands
    3. Scroll down further to Bot Permissions and select the permissions that you wish to assign your bot with. (Probably "Send Messages" )
    4. Open the generated authorization URL in your browser.
    5. Select a server.
    6. Click on Authorize.
  5. Connecting your bot to Discord

    1. Right click the project and "Manage User Secrets" and copy from "secrets.example.json" and fill in the right values
    2. Add the following code:
    var client = new DiscordSocketClient();
    await client.LoginAsync(TokenType.Bot, token);
    await client.StartAsync();
    // Block this task until the program is closed.
    await Task.Delay(-1);
    
    1. The token is the token from the Discord Bot.
    2. Start your app and you should see the bot come online in the Discord server.
  6. Making your bot do stuf