在Discord Bot中使用YouTube API

问题描述

我在考虑一个discord Bot,如果您是使用YouTube API的YouTube频道的子频道,那么它会给您一个子角色,但我真的不知道如何在Bot中使用YouTube API,所以我的问题是我该如何添加向我的机器人发送YouTube Data API吗?

解决方法

您实际上无法为服务器中的订阅者赋予角色,因为不和谐和youtube的数据库都无法连接,因此您无法获得不和谐的用户,该用户是特定youtube频道的订阅者。但是,您可以在漫游器中使用google-api-python-client将其与youtube连接并获取有关特定频道的信息或搜索视频,而您需要youtube API key才能这样做。

在这里如何编码-

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.