Discord Bot for Youtube Search

import os
import discord
from datetime import datetime
from discord.ext import commands, tasks
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError

# Environment variables
TITLE_KEYWORD = os.environ['TITLE_KEYWORD'].lower()  # Environment variable for title keyword, converted to lowercase

# Global variable
PUBLISHED_AFTER = "2024-01-01T00:00:00Z"

# Initialize the Discord bot
bot = commands.Bot(command_prefix='!')

# Function to create YouTube API client
def youtube_api_client():
    return build('youtube', 'v3', developerKey=YOUTUBE_API_KEY)

About this template

A Discord bot that searches and posts new YouTube videos to a discord channel hourly based on a specific tag or keyword.

Introduction to the Discord Bot for YouTube Search Template

Welcome to the Discord Bot for YouTube Search template! This template allows you to create a Discord bot that automatically searches for new YouTube videos based on a specific keyword or tag and posts them to a Discord channel on an hourly basis. This is perfect for communities that want to stay updated on the latest content related to their interests.

Clicking Start with this Template

To begin using this template, simply click on the "Start with this Template" button. This will initialize the template within the Lazy platform, pre-populating the code in the Lazy Builder interface.

Initial Setup: Adding Environment Secrets

Before you can use the bot, you'll need to set up some environment secrets within the Lazy Builder. These secrets include:

  • DISCORD_BOT_TOKEN: Your Discord bot token, which you can obtain from the Discord Developer Portal.
  • DISCORD_CHANNEL_ID: The ID of the Discord channel where the bot will post messages.
  • YOUTUBE_API_KEY: Your YouTube API key, which you can get from the Google Cloud Console.
  • YOUTUBE_SEARCH_QUERY: The search query the bot will use to find new videos on YouTube.
  • TITLE_KEYWORD: A keyword that must be present in the video title for it to be posted to your Discord channel.

To set these up, navigate to the Environment Secrets tab within the Lazy Builder and enter the corresponding values for each secret.

Test: Pressing the Test Button

Once you have configured the environment secrets, press the "Test" button to deploy the app. The Lazy CLI will handle the deployment, and you won't need to worry about installing libraries or setting up your environment.

Entering Input: Filling in User Input

There is no user input required through the CLI for this template, as all necessary configurations are handled through environment secrets.

Using the App

After pressing the "Test" button and deploying the app, the bot will start running on the Lazy platform. It will automatically check for new YouTube videos every hour and post them to the specified Discord channel if they match the search query and title keyword criteria.

Integrating the App

To integrate the bot into your Discord server, you will need to invite the bot using the Discord Developer Portal. Here are the steps to do so:

  • Go to the Discord Developer Portal and navigate to your bot's page.
  • Under the "OAuth2" tab, select the "bot" scope to generate an invite link.
  • Choose the permissions your bot will need, such as "Send Messages" and "Read Message History."
  • Use the generated link to invite the bot to your Discord server.

Once the bot is part of your server and the app is running on Lazy, it will begin its hourly search for new videos and share them in the designated channel.

If you need further assistance or have any questions, the Lazy platform provides support to help you get the most out of your new Discord bot for YouTube searches.

Last published
June 15, 2024

More templates like this

PDF Data Extraction and Excel Transfer

An app for extracting name, phone number, and email data from PDF files and transferring it to Excel.


Discord Ticketbot Template

A simple Discord Ticketbot for your Discord Support Department. This Template and Bot is fully customizable but already build so that you can use it right away. You need a bot token from https://discord.com/developers/applications for your bot to work. These are the steps needed to get your token: "1. 🌐 Go to the Discord Developer Portal. 🌐\n" + "2. 🆕 Create a new application and navigate to the 'Bot' section. 🤖\n" + "3. 📋 Under the 'TOKEN' section, click 'Reset Token' to get your Discord bot token and confirm by clicking 'Yes, do it'. 🔑\n" + "4. 🤖 If your bot will have any ability to read/reply to messages, then under the 'BOT' section, enable the slider titled 'Message Content Intent' ✅" + "5. 🔐 Set the 'DISCORD_BOT_TOKEN' in the Env Secrets tab with your bot token from step 3. 🔐\n" + "For bot permissions, it's recommended to start with basic permissions and adjust as needed for your app's functionality.🚀") If you encounter any bugs, please tell Lazy to fix them and report them on the Official Lazy AI Discord to @D4vidG4merLP. Credits: @meow - the Discord bot slash command template @mrlazy.notlazy - supporting me And the Biggest Thank you. You for using this template ❤️


GPT-4 Exam Generator

This app uses GPT-4 to generate a PDF of a new exam based on an uploaded PDF of a past exam.

Discord Bot for Youtube Search