railway-music
v1.3.5
Published
A package that complies with railway's rules on playing music, but still lets you play music.
Downloads
6
Readme
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:
Object
Properties: {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: YesNotes:
Play Function
MusicClient.play(PlayOptions);
- PlayOptions:Type:
Object
Properties: {message:Discord.js Message Object
, song:String
}Required: Yes
Stop Function
MusicClient.stop(Message);
- Message:Type:
Discord.js Message Object
Required: Yes
SetVolume Function
MusicClient.setVolume(VolumeOptions);
- VolumeOptions:Type:
Object
Properties: {message:Discord.js Message Object
, volume:Number
}Required: Yes
Stop Function
MusicClient.skip(Message);
- Message:Type:
Discord.js Message Object
Required: Yes
Pause Function
MusicClient.pause(Message);
- Message:Type:
Discord.js Message Object
Required: Yes
Resume Function
MusicClient.resume(Message);
- Message:Type:
Discord.js Message Object
Required: Yes
LoopTrack Function
MusicClient.loopTrack(Message);
- Message:Type:
Discord.js Message Object
Required: Yes
LoopQueue Function
MusicClient.loopQueue(Message);
- Message:Type:
Discord.js Message Object
Required: Yes
- If you have any questions about this package join the official railway discord server and ping me (Korabi <3#6251) in the chat.