Skip to content

Instantly share code, notes, and snippets.

@iggyvolz
Created October 28, 2018 19:40
Show Gist options
  • Save iggyvolz/01e9d8916fb5fc7b833aef75b3cec783 to your computer and use it in GitHub Desktop.
Save iggyvolz/01e9d8916fb5fc7b833aef75b3cec783 to your computer and use it in GitHub Desktop.
<?php
require_once "config.php"; // defines YOUTUBE_PLAYLIST (the id of the playlist), YOUTUBE_TOKEN (https://www.slickremix.com/docs/get-api-key-for-youtube/), DISCORD_TOKEN (https://github.com/reactiflux/discord-irc/wiki/Creating-a-discord-bot-&-getting-a-token), and DISCORD_CHANNEL (right-click channel, copy ID)
require_once __DIR__.'/vendor/autoload.php'; // composer require restcord/restcord
use RestCord\DiscordClient;
$conts=json_decode(file_get_contents("https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails&maxResults=50&playlistId=".YOUTUBE_PLAYLIST."&key=".YOUTUBE_TOKEN));
$count=count($conts->items);
$index=random_int(0,$count);
$videoid=$conts->items[$index]->contentDetails->videoId;
$discord = new DiscordClient(['token' => DISCORD_TOKEN]); // Token is required
$discord->channel->createMessage(['channel.id' => DISCORD_CHANNEL, 'content' => 'VGM of the Day - '.date("m/d/y").' https://www.youtube.com/watch?v='.$videoid]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment