neqt
neqt

Reputation: 31

Use YouTube API in Discord Bot

I was thinking about a Discord Bot that gives you a sub role if you are sub of a YouTube Channel using YouTube API but I really don't know how to use YouTube API in my Bot so my Question is how could I add YouTube Data API to my Bot ?

Upvotes: 2

Views: 4178

Answers (1)

Harjot
Harjot

Reputation: 943

You cannot actually give a role to the subscribers in a server as discord and youtube's databases are not connected anyhow, so you cannot get a discord user which is a subscriber of a specific youtube channel. However, you can use google-api-python-client in your bot to connect it with youtube and get info about a specific channel or search a video, you will require a youtube API key to do so.

Heres how you can code it -

from googleapiclient.discovery import build

@client.command()
async def ytsearch(ctx, query: str):
    youtube = build("youtube", "v3", developerKey=YT_Key)
    search_response = youtube.search().list(q=<query>, part="id,snippet", maxResults=5).execute()
    await ctx.send(search_response) # It will send the data in a .json format.

Upvotes: 1

Related Questions