A Discord bot that announces new videos from a specified YouTube channel in a designated Discord channel. The bot supports setup via commands and checks for new videos periodically.
- Automatic Announcements: Automatically post announcements in a Discord channel when a new video is uploaded to a specified YouTube channel.
- Setup Commands: Configure the bot with
/setup
to set the YouTube and Discord channels for announcements. - Manual Video Check: Use
/newestvideo
to manually fetch and display the latest video from the YouTube channel. - Configuration Management: Admin commands to clear settings or update the channels through
/reset
and/setup
.
-
Download the Bot Package
Download the
.tar
package of the bot from the releases page or import it in to the server. -
Upload the Package to Velvox Gamehosting
- Buy your bot (Discord bot.py) and use "Python Generic"
- Then go to the gamepanel and go to "your server" > files and drop the .tar file in to the
/home/container/
directory, and extract it. - Create a database in the "Database" tab and write the login information down.
-
Configure the Bot
- Open the
bot.py
and edit the thedef get_mysql_connection
and put the correct login data in to the file.db_config = { 'host': 'yourdatabasehost', # MySQL database host IP 'user': 'yourdatabaseuser', # MySQL user 'password': 'yourdatabasepassword', # MySQL password 'database': 'yourdatabasename' # MySQL database name }
- Then scroll down to the last line of code to the
bot.run()
statement. and add your bot token you can get this at the Discord Developer Portal.# Run the bot with your token bot.run()
- Make sure that the MySQL database has the necessary tabels, by default the bot generates them automaticly but it could error.
CREATE TABLE IF NOT EXISTS channel_settings ( id INT AUTO_INCREMENT PRIMARY KEY, discord_channel_id BIGINT NOT NULL, youtube_channel_id VARCHAR(100) NOT NULL, last_announced_video_id VARCHAR(100) DEFAULT NULL );
- Open the
-
Install Required Packages
- By default the panel should install the default and neccasary packages. If you get any errors contact thier support.
-
Run the Bot
- If you configured your bot the right way when you click "Start" in the gamepanel it should start and you can start using your bot!
- Ensure it has the right permissions set in the Discord Developer Portal.
- Go ahead to the commands section. And you can setup your bot inside your discord server.
- Ensure you have Python 3.8+ installed.
- Create a bot application on the Discord Developer Portal and obtain your bot token.
- Set up a MySQL database and ensure you have the necessary credentials.
-
Clone the Repository
git clone https://github.com/yourusername/koenfred19-discord-bot.git cd koenfred19-discord-bot
-
Install Dependencies
pip install -r requirements.txt
Make sure to have
discord.py
,aiohttp
,pymysql
, andpytz
listed inrequirements.txt
. -
Configure Database
-
Update
db_config
inbot.py
with your MySQL database credentials:db_config = { 'host': 'yourdatabasehost', # MySQL database host IP 'user': 'yourdatabaseuser', # MySQL user 'password': 'yourdatabasepassword', # MySQL password 'database': 'yourdatabasename' # MySQL database name }
-
Ensure your database has the required tables. You can use the following SQL script:
CREATE TABLE IF NOT EXISTS channel_settings ( id INT AUTO_INCREMENT PRIMARY KEY, discord_channel_id BIGINT NOT NULL, youtube_channel_id VARCHAR(100) NOT NULL, last_announced_video_id VARCHAR(100) DEFAULT NULL );
-
-
Set Up Bot Token
-
Replace the placeholder token in
bot.run()
with your bot token:bot.run('YOUR_BOT_TOKEN')
-
-
Run the Bot
python bot.py
All the commands work with Discord Slashcommands
-
/setup
Description: Configure the YouTube channel and Discord channel for announcements. This currently only supports one channel, I think about adding this in the future.
Usage:
/setup <youtube_channel_id> <discord_channel_id>
Permissions: Requires administrator permissions.
-
/newestvideo
Description: Fetch and display the latest video from the configured YouTube channel.
Usage:
/newestvideo
-
/reset
Description: Clear all channel settings from the database. (Use this when you accedently added 2 channels and the bot doesnt work anymore.)
Usage:
/reset
Permissions: Requires administrator permissions.
This bot is licensed under the GNU General Public License v3.0. See the LICENSE
file for more details.