Search…
Getting Started
index.js
const { Client } = require('discord.js');
const { Poru } = require('poru');
const nodes = [
{
id: "main_node",
hostname:"localhost",
port: 8080,
password: "iloveyou3000"
}
]
const client = new Client();
​
client.poru = new Poru(client,nodes,PoruOptions)
​
​
​
client.poru.on('trackStart', (player, track) => {
player.textChannel.send(`Now playing \`${track.title}\``);
});
​
​
client.on('ready', () => {
console.log('Ready!');
client.poru.init(client);
});
​
​
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
if (!interaction.member.voice.channel) return interaction.reply({ content: `Please connect with voice channel `, ephemeral: true });
​
const track = interaction.options.getString('track');
​
const res = await client.poru.resolve(track);
​
if (res.loadType === "LOAD_FAILED") {
return interaction.reply(`Failed to load track`);
} else if (res.loadType === "NO_MATCHES") {
return interaction.reply('No source found!');
}
​
//create connection with discord voice channnel
const player = client.poru.createConnection({
guildId: interaction.guild.id,
voiceChannel: interaction.member.voice.channelId,
textChannel: interaction.channel,
deaf: true
});
if (res.loadType === 'PLAYLIST_LOADED') {
for (const track of res.tracks) {
trackk.info.requester = interaction.user;
player.queue.add(track);
}
​
interaction.reply(`${res.playlistInfo.name} has been loaded with ${res.tracks.length}`);
} else {
const track = res.tracks[0];
track.info.requester = interaction.user;
player.queue.add(track);
interacton.reply(`Queued Track \n \`${track.title}\``);
}
​
if (!player.isPlaying && player.isConnected) player.play();
});
​
client.login('TOKEN');
​
Copy link