Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

KagChi/lavalink-glitch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lavalink-glitch

Lavalink on glitch

Special Thanks To

  1. Hideki Shibata#1870
  2. Orchit#8776
  3. Zen Shibata#6784
  4. Allvaa

Connecting

  • Lavalink's port will always 443
  • Default password youshallnotpass
  • using custom lavalink client

Important notes:

  • To keep this 24/7 you need to make an account on UptimeRobot service, and make HTTP request to your app every 5 minutes. For example, if your app is named lavalink-glitch then make HTTP request to https://lavalink-glitch.glitch.me
  • Glitch boost to keep 24/7 (glitch banned uptimerobot)
  • Uptimerobot alternative Link
  • Google appscript
  • Do not forget to set your password (in application.yml file)

Advantages:

  • Use java 13 :3
  • Easy setup
  • Using Dev build

Example:

  • Latest Shoukaku (v1.6.x)
const { Client } = require('discord.js');
const { Shoukaku } = require('shoukaku');
 
const LavalinkServer = [{ name: 'my-lavalink-server', host: 'lavalink-glitch.glitch.me', port: 443, auth: 'youshallnotpass', secure: true }];
const ShoukakuOptions = { moveOnDisconnect: false, resumable: false, resumableTimeout: 30, reconnectTries: 2, restTimeout: 10000 };
 
class ExampleBot extends Client {
    constructor(opts) {
        super(opts);
        this.shoukaku = new Shoukaku(this, LavalinkServer, ShoukakuOptions);
    }
 
    login(token) {
        this._setupShoukakuEvents();
        this._setupClientEvents();
        return super.login(token);
    }
 
    _setupShoukakuEvents() {
        this.shoukaku.on('ready', (name) => console.log(`Lavalink ${name}: Ready!`));
        this.shoukaku.on('error', (name, error) => console.error(`Lavalink ${name}: Error Caught,`, error));
        this.shoukaku.on('close', (name, code, reason) => console.warn(`Lavalink ${name}: Closed, Code ${code}, Reason ${reason || 'No reason'}`));
        this.shoukaku.on('disconnected', (name, reason) => console.warn(`Lavalink ${name}: Disconnected, Reason ${reason || 'No reason'}`));
    }
 
    _setupClientEvents() {
        this.on('message', async (msg) => {
            if (msg.author.bot || !msg.guild) return;
            if (!msg.content.startsWith('$play')) return;
            if (this.shoukaku.getPlayer(msg.guild.id)) return;
            const args = msg.content.split(' ');
            if (!args[1]) return;
            const node = this.shoukaku.getNode();
            let data = await node.rest.resolve(args[1]);
            if (!data) return;
            const player = await node.joinVoiceChannel({
                guildID: msg.guild.id,
                voiceChannelID: msg.member.voice.channelID
            }); 
            player.on('error', (error) => {
                console.error(error);
                player.disconnect();
            });
            for (const event of ['end', 'closed', 'nodeDisconnect']) player.on(event, () => player.disconnect());
            data = data.tracks.shift();
            await player.playTrack(data); 
            await msg.channel.send("Now Playing: " + data.info.title);
        });
        this.on('ready', () => console.log('Bot is now ready'));
    }
}
 
new ExampleBot()
    .login('token')
    .catch(console.error);

Example bot here