2.7 KiB
Discord Bot Setup Guide
This guide explains how to create, configure, and run a Discord bot that responds to commands in a specific channel and reads data from a Google Sheet.
Step 1: Create Your Bot on Discord
-
Go to the Discord Developer Portal
Visit Discord Developer Portal. -
Create a New Application
Click on "New Application" and give your bot a name (e.g., "MyBot"). -
Add a Bot to the Application
Once the application is created, click on "Bot" in the left menu and then click "Add Bot". -
Copy the Authentication Token
Under "TOKEN", click on "Copy" to copy your token (keep it safe and don't share it!).
Step 2: Install Python Dependencies
If you don't have Python installed, download it here: Python.
Then, install the required libraries via pip:
pip install discord.py pandas gspread oauth2client
discord.py: for interacting with the Discord API.pandas: for manipulating the Google Sheets data.gspreadandoauth2client: for accessing Google Sheets (if your file is private).
Step 5: Add Your Authorized Channel ID
- Replace
AUTHORIZED_CHANNEL_ID = 123456789012345678with the ID of the channel where you want to allow the command. - To get the channel ID, enable Developer Mode in Discord (User Settings > Advanced > Developer Mode), then right-click your channel and select "Copy ID".
Step 6: Obtain Your Google Sheet URL
- If your Google Sheet is public: Go to your Google Sheets file, then click on "File" > "Publish to the web" and copy the URL.
- If your Google Sheet is private, you will need to configure a Google API key and use it with
gspread(this requires additional setup).
For a public file, the URL will look like this:
https://docs.google.com/spreadsheets/d/YOUR_FILE_ID/edit#gid=0
Replace "YOUR_GOOGLE_SHEET_URL" with your actual URL in the code.
Step 8: Run Your Bot
- Save your
bot.pyfile and make sure your Discord token is correct. - Run the bot using the following command in your terminal:
python bot.py
Step 9: Invite the Bot to Your Server
- Go to the Discord Developer Portal and in "OAuth2" -> "URL Generator".
- Check the required permissions like
botandmessages.readto allow your bot to read and send messages. - Copy the generated URL and open it in your browser to invite your bot to your Discord server.
Summary
- The bot only responds in a specific channel (using the channel ID).
- It ignores the command in other channels.
- It reads data from the Google Sheet only when the
!siegecommand is called.