This Discord bot allows you to track and display the number of folders in specified directories on your server. The bot creates and updates voice channels for each tracked folder, displaying the current folder count. Additionally, it creates total count channels for aggregated counts of specific folders.
Before running the bot, make sure you have the following:
- Python 3 installed on your system.
- Discord account and a registered bot on the Discord Developer Portal.
- Bot token obtained from the Discord Developer Portal.
-
Clone or download the repository:
git clone https://github.com/sureshfizzy/Discord-folder-count-bot.git cd Discord-folder-count-bot
-
Install required Python packages:
pip install discord.py
-
Create a Discord Application:
- Go to the Discord Developer Portal.
- Click on "New Application" and give it a name.
- Navigate to the "Bot" tab on the left sidebar.
- Click "Add Bot" and confirm.
-
Get the Bot Token:
- Under the Bot section of your application, click "Copy" to copy the bot token.
- Keep this token secure, as it grants access to your bot.
-
Invite the Bot to Your Server:
- Still in the Discord Developer Portal, navigate to the OAuth2 tab.
- Scroll down to the "OAuth2 URL Generator" section.
- Select the appropriate OAuth2 scopes and permissions for your bot.
- Copy the generated OAuth2 URL and paste it into your browser.
- Select the server where you want to add the bot and authorize it.
-
Create a Role for the Bot:
- In your Discord server, navigate to the server settings.
- Click on "Roles" and then "Create Role."
- Name the role (e.g., "Bot") and customize its permissions.
-
Grant Necessary Permissions:
- Assign the bot role the necessary permissions based on the bot's functionality.
- Ensure that the bot has permissions to read and send messages in the channels where it will operate.
- Grant additional permissions as needed, such as managing messages, embedding links, etc.
-
Assign the Bot Role:
- Go to the member list in your server.
- Find the bot's username and click on it.
- Assign the bot role you created to the bot.
-
Test Permissions:
- Test the bot's permissions by running it in your server.
- Make sure it can perform its intended actions without any issues.
-
Open
discord_bot.py
in a text editor. -
Replace
'YOUR_TOKEN'
with the actual bot token obtained from the Discord Developer Portal:TOKEN = 'YOUR_TOKEN'
-
Update the
folders
dictionary with the folders you want to track and their corresponding paths:folders = { "Movies": "/path/to/Movies", "Movies2": "/path/to/Movies", "Series": "/path/to/Series", "Series2": "/path/to/Series", # Add other folders with their paths here }
-
Open a terminal and navigate to the bot directory.
-
Run the bot using the following command:
python3 discord_bot.py
-
The bot will start running and will print "Bot is ready" once it is connected to Discord.
-
Create a service file for the bot:
sudo nano /etc/systemd/system/discord-bot.service
-
Add the following configuration to the file (modify paths accordingly):
[Unit] Description=Discord Bot - Folder Count Tracker After=network.target [Service] ExecStart=/usr/bin/python3 /path/to/discord_bot.py WorkingDirectory=/path/to/discord-bot-directory Restart=always User=your_username Group=your_group [Install] WantedBy=default.target
-
Save the file and exit the text editor.
-
Start the service:
sudo systemctl start discord-bot
-
Enable the service to start on boot:
sudo systemctl enable discord-bot
Now, your Discord bot will run as a system service.
Ensure the bot has the necessary permissions on your Discord server:
-
Create a new role for the bot.
-
Assign the role the following permissions:
- Read Messages
- Send Messages
- Connect
- View Channel
-
Add the bot to your server and assign the role to the bot.
-
The bot should now have the required permissions to create and manage channels.
Once the bot is running and added to your server, it will automatically create and update channels in the specified category. The channels will display the current count of folders in the tracked directories. The bot updates counts every 24 hours (You can update the delay according to your needs).