1.3.5 • Published 2 years ago

railway-music v1.3.5

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Railway-Music:

Railway-Music is an npm package designed to not break railway's Terms of Serivce, but still let you play music.

This package was made because lot of people were having trouble with hosting their music bots on railway.

About the package:

Railway-Music uses Erela.js and Lavalink in a combination that does not download any DMCA protected content, therefor being in compliance with railway's Terms of Serivce, You can check out the Erela.js docs for more info on MusicClient.manager and Events. Note: Where ever Erela.js Docs say "client" that will translate to "MusicClient" if you are using the examples provided below.

Install:

npm install railway-music

or

yarn add railway-music

Music Bot Example:

const RailwayMusic = require("railway-music");
const MusicClient = new RailwayMusic({
  clientID: "ID",
  clientToken: "TOKEN",
  defaultLogs: true,
});
const discord = require("discord.js");
const client = new discord.Client({ intents: 32767 });
client.login("TOKEN");

// Log it when the client is ready.
client.on("ready", () => {
  console.log("Logged in.");
});

// Play command
client.on("messageCreate", async (m) => {
  if (m.author.bot || !m.content.toLowerCase().startsWith("!play")) return;
  try {
    const response = await MusicClient.play({
      message: m,
      song: m.content.replace("!play", "").trim(),
    });
    return m.reply({
      embeds: [
        new discord.MessageEmbed()
          .setTitle("Enqueueing")
          .setDescription(
            `Enqueueing: **${response.tracks[0].title}**, requested by \`${response.tracks[0].requester.tag}\` `
          ),
      ],
    });
  } catch (e) {
    return m.reply({
      embeds: [
        new discord.MessageEmbed().setTitle("Error").setDescription(String(e)),
      ],
    });
  }
});

// Stop | Leave command
client.on("messageCreate", async (m) => {
  if (m.author.bot || !m.content.toLowerCase().startsWith("!stop")) return;
  try {
    await MusicClient.stop(m);
    return m.reply({
      embeds: [
        new discord.MessageEmbed()
          .setTitle("Deleted Queue")
          .setDescription("Deleted the queue and exited the voice channel."),
      ],
    });
  } catch (e) {
    return m.reply({
      embeds: [
        new discord.MessageEmbed().setTitle("Error").setDescription(String(e)),
      ],
    });
  }
});

// Skip command
client.on("messageCreate", async (m) => {
  if (m.author.bot || !m.content.toLowerCase().startsWith("!skip")) return;
  try {
    await MusicClient.skip(m);
  } catch (e) {
    return m.reply({
      embeds: [
        new discord.MessageEmbed().setTitle("Error").setDescription(String(e)),
      ],
    });
  }
});

// Pause command
client.on("messageCreate", async (m) => {
  if (m.author.bot || !m.content.toLowerCase().startsWith("!pause")) return;
  try {
    await MusicClient.pause(m);
    return m.reply({
      embeds: [
        new discord.MessageEmbed()
          .setTitle("Paused")
          .setDescription("Paused the current song."),
      ],
    });
  } catch (e) {
    return m.reply({
      embeds: [
        new discord.MessageEmbed().setTitle("Error").setDescription(String(e)),
      ],
    });
  }
});

// Resume command
client.on("messageCreate", async (m) => {
  if (m.author.bot || !m.content.toLowerCase().startsWith("!resume")) return;
  try {
    await MusicClient.resume(m);
    return m.reply({
      embeds: [
        new discord.MessageEmbed()
          .setTitle("Resumed")
          .setDescription("Resumed the current song."),
      ],
    });
  } catch (e) {
    return m.reply({
      embeds: [
        new discord.MessageEmbed().setTitle("Error").setDescription(String(e)),
      ],
    });
  }
});

// Volume command
client.on("messageCreate", async (m) => {
  if (m.author.bot || !m.content.toLowerCase().startsWith("!volume")) return;
  try {
    await MusicClient.setVolume({
      message: m,
      volume: Number(m.content.replace("!volume", "").replace(/ /g, "").trim()),
    });
    return m.reply({
      embeds: [
        new discord.MessageEmbed()
          .setTitle("Volume set")
          .setDescription(
            `Set volume to: ${m.content
              .replace("!volume", "")
              .replace(/ /g, "")
              .trim()}`
          ),
      ],
    });
  } catch (e) {
    return m.reply({
      embeds: [
        new discord.MessageEmbed().setTitle("Error").setDescription(String(e)),
      ],
    });
  }
});

// Send a message to the channel when there is no more music left to play, and leave the voice channel.
MusicClient.manager.on("queueEnd", (player) => {
  const embed = new discord.MessageEmbed()
    .setTitle("Queue Ended")
    .setDescription(
      "There is no more songs to play! I have to leave the channel friends :("
    );

  client.channels.cache.get(player.textChannel).send({ embeds: [embed] });
  player.destroy();
});

// Send a message when a song starts playing
MusicClient.manager.on("trackStart", (player, track) => {
  const embed = new discord.MessageEmbed()
    .setTitle("Music Playing")
    .setDescription(
      `Now playing: **${track.title}**, requested by \`${track.requester.tag}\`.`
    );
  client.channels.cache.get(player.textChannel).send({ embeds: [embed] });
});
  • Apologies on the unorganized commands, but I wanted to have it be simple.

Documentation:

  • Note: If a property has "?" at the end of its name, it means said property is optional.

MusicClient Constructor

new RailwayMusic(MusicClientOptions);
  • MusicClientOptions:Type: ObjectProperties: {nodes?: Array<{host: String, port: Number, password: String}>, autoReply?: Object<{enabled: Boolean, funtionNameTitle?: String, functionNameDescription?: String, embedColor: DiscordJsColorResolvable}>, defaultLogs: Boolean, clientID: String, clientToken: String}Required: Yes

  • Notes:

Play Function

MusicClient.play(PlayOptions);
  • PlayOptions:Type: ObjectProperties: {message: Discord.js Message Object, song: String}Required: Yes

Stop Function

MusicClient.stop(Message);
  • Message:Type: Discord.js Message ObjectRequired: Yes

SetVolume Function

MusicClient.setVolume(VolumeOptions);
  • VolumeOptions:Type: ObjectProperties: {message: Discord.js Message Object, volume: Number}Required: Yes

Stop Function

MusicClient.skip(Message);
  • Message:Type: Discord.js Message ObjectRequired: Yes

Pause Function

MusicClient.pause(Message);
  • Message:Type: Discord.js Message ObjectRequired: Yes

Resume Function

MusicClient.resume(Message);
  • Message:Type: Discord.js Message ObjectRequired: Yes

LoopTrack Function

MusicClient.loopTrack(Message);
  • Message:Type: Discord.js Message ObjectRequired: Yes

LoopQueue Function

MusicClient.loopQueue(Message);
  • Message:Type: Discord.js Message ObjectRequired: Yes
1.3.5

2 years ago

1.3.4

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

3 years ago

1.2.11

3 years ago

1.2.10

3 years ago

1.2.9

3 years ago

1.2.8

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago