Discord.NET workshop for Kennisweekend
All steps are also described here with images: https://docs.discordnet.dev/guides/getting_started/first-bot.html
-
Create a Discord account
-
Install the Discord.Net package in your solution (done already in project)
-
Create a bot on: https://discord.com/developers/applications/
- Click "New Application"
- Fill in the details and click save
- Go to the "Bot" tab on the left and Click "Add Bot" if needed
- 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")
- Go to the "Privileged Gateway Intents" and check the last one "MESSAGE CONTENT INTENT", so our bot can read server messages.
-
Add your bot to a server
- Go to "OAuth2" tab
- Scroll down to OAuth2 URL Generator and under Scopes tick
bot
andapplications.commands
- Scroll down further to Bot Permissions and select the permissions that you wish to assign your bot with. (Probably "Send Messages" )
- Open the generated authorization URL in your browser.
- Select a server.
- Click on Authorize.
-
Connecting your bot to Discord
- Right click the project and "Manage User Secrets" and copy from "secrets.example.json" and fill in the right values
- 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);
- The token is the token from the Discord Bot.
- Start your app and you should see the bot come online in the Discord server.
-
Making your bot do stuf