• Documentation
MoonLink.js is a simple package for lavalink client, perfect for you to create your discord bot with songs, and very simple and easy to use.
npm: npm install moonlink.js
yarn: yarn add moonlink.js
pnpm: pnpm install moonlink.js
Requirements are, have a node above version
1.16 >==
support packages
const {
Client,
GatewayIntentBits
} = require('discord.js') //importing discord.js library
const {
MoonlinkManager
} = require('moonlink.js') // importing moonlink.js package
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildVoiceStates
]
}) //creating a client for the bot
//------- (package configuration) ----------//
client.moon = new MoonlinkManager([{
host: 'localhost',
port: 2333,
secure: true,
password: 'MyPassword'
}], { /* Option */ }, (guild, sPayload) => {
client.guilds.cache.get(guild).shard.send(JSON.parse(sPayload))
})
client.moon.on('nodeCreate', (node) => {
console.log(`${node.host} was connected`)
}) //emit to the console the node was connected to
client.moon.on('trackStart', async(player, track) => {
client.channels.cache.get(player.textChannel).send(`${track.title} is playing now`) //when the player starts it will send a message to the channel where the command was executed
})
client.moon.on('trackEnd', async(player, track) => {
client.channels.cache.get(player.textChannel).send(`track is over`) //when the player starts it will send a message to the channel where the command was executed
})
client.on('ready', () => {
client.moon.init(client.user.id); //initializing the package
});
client.on('raw', (data) => {
client.moon.packetUpdate(data) //this will send to the package the information needed for the package to work properly
})
client.on('interactionCreate', async(interaction) => {
if (!interaction.isChatInputCommand()) return;
if(interaction.commandName == 'play') {
if (!interaction.member.voice.channel) return interaction.reply({
content: `you are not on a voice channel`,
ephemeral: true
})
let query = interaction.options.getString('query');
let player = client.moon.players.create({
guildId: interaction.guild.id,
voiceChannel: interaction.member.voice.channel.id,
textChannel: interaction.channel.id,
autoPlay: true
}); //creating a player
if (!player.connected) player.connect({
setDeaf: true,
setMute: false
}) // if the player is not connected it will connect to the voice channel
let res = await client.moon.search(query) // will do a search on the video informed in the query
if (res.loadType === "LOAD_FAILED") {
return interaction.reply({
content: `:x: Load failed. `
}); //if there is an error when loading the tracks, it informs that there is an error
} else if (res.loadType === "NO_MATCHES") {
return interaction.reply({
content: `:x: No matches!`
}); // nothing was found
}
if (res.loadType === 'PLAYLIST_LOADED') {
interaction.reply({
content: `${res.playlistInfo.name} this playlist has been added to the waiting list`
})
for (const track of res.tracks) {
//if it's a playlist it will merge all the tracks and add it to the queue
player.queue.add(track);
}
} else {
player.queue.add(res.tracks[0])
interaction.reply({
content: `${res.tracks[0].name} was added to the waiting list`
})
}
if (!player.playing) player.play()
}
}
});
client.login(process.env["DISCORD_TOKEN"])
Enter the documentation site to understand more about the package, there are many more examples MoonLink Docs
You can get support on our discord server MoonLink - Support(Updated)
meaning of emojis
1Lucas1.apk 💻📖💡🚇🤔 🚧💬👀🔧 |
MotoG.js 💻💡🤔💬🎨 |
ItzGG 🐛 |
Nah 🐛 |
SuperPlayerBots 🐛 |
ddemile 🐛 |
Tasty-Kiwi 🐛 |