Skip to content

Instantly share code, notes, and snippets.

@Caaz
Last active June 8, 2022 00:42
Show Gist options
  • Save Caaz/75bbffe474ee39a30fb8ac685147f6b7 to your computer and use it in GitHub Desktop.
Save Caaz/75bbffe474ee39a30fb8ac685147f6b7 to your computer and use it in GitHub Desktop.
const {MessageEmbed, WebhookClient} = require('discord.js');
const TTAPI = require('ttapi');
const secrets = require('./secrets.json');
const turntable = new TTAPI(secrets.AUTH, secrets.USERID, secrets.room_id);
const webhook = new WebhookClient({id: secrets.webhook_id, token: secrets.webhook_token});
turntable.on('ready', _ => {
turntable.roomRegister(secrets.room_id);
});
turntable.on('newsong', data => {
const song = data.room.metadata.current_song;
const embed = new MessageEmbed()
.setTitle(song.djname + ' via Turntable')
.setURL('https://turntable.fm/' + secrets.room_id)
.addFields(
{name: 'Artist', value: song.metadata.artist, inline: true},
{name: 'Title', value: song.metadata.song, inline: true},
)
.setImage(song.metadata.coverart);
if (song.source === 'yt') {
embed.setDescription('https://youtu.be/' + song.sourceid);
}
webhook.send({
username: 'Turntable',
avatarURL: 'https://turntable.fm/roommanager_assets/stickers/turntable.png',
embeds: [embed],
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment