UNPKG

8.61 kBMarkdownView Raw
1# Imagine a Music...
2
3![MoonImage](https://media.discordapp.net/attachments/1211812380850528267/1213558016771625011/48_Sem_Titulo_20231206185046.png?ex=65f5e8fa&is=65e373fa&hm=19170abb2481ba1b9a24bbe136b428bc6cfbfedc95cf53498a10bfbcf735c53d&)
4[![NPM](https://nodei.co/npm/moonlink.js.png)](https://nodei.co/npm/moonlink.js)
5
6[![Made with ♥️ in - Brazil](https://img.shields.io/badge/Made_with_♥️_in-Brazil-ED186A?style=for-the-badge)](https://github.com/1Lucas1apk)
7
8[![Codacy Badge](https://app.codacy.com/project/badge/Grade/7dd9288acdc94dacaa11ad80f36a9bd3)](https://www.codacy.com/gh/1Lucas1apk/moonlink.js/dashboard?utm_source=github.com&utm_medium=referral&utm_content=1Lucas1apk/moonlink.js&utm_campaign=Badge_Grade) [![Downloads](https://img.shields.io/npm/dt/moonlink.js.svg?color=3884FF)](https://www.npmjs.com/package/moonlink.js) [![Version](https://img.shields.io/npm/v/moonlink.js.svg?color=3884FF&label=version)](https://www.npmjs.com/package/moonlink.js) [![install size](https://packagephobia.com/badge?p=moonlink.js)](https://packagephobia.com/result?p=moonlink.js) ![node](https://img.shields.io/node/v/moonlink.js) [![Netlify Status](https://api.netlify.com/api/v1/badges/4f4a2a64-a8db-4db3-ad1d-0c4ac7274d0e/deploy-status)](https://app.netlify.com/sites/moonlinkjs/deploys)
9
10Envision a musical journey where creativity knows no bounds, accompanied by the enchantment of the holiday season. 🌌 Moonlink.js invites you to unlock your complete musical potential, designed exclusively for Lavalink clients. Step into a world of seamless communication and fluid interaction, where Moonlink.js elevates your projects to new heights, sprinkled with holiday charm. With full TypeScript support, it empowers your creativity and productivity. 🎵
11
12## Table of Contents
13
14- [Features](#features)
15- [Documentation](#documentation)
16- [Installation](#installation)
17- [How to Use](#how-to-use)
18- [Attributions](#attributions)
19- [Contributors](#contributors)
20- [Final Thanks](#final-thanks)
21- [License](#license)
22- [Support](#support)
23
24## Features
25
26**Moonlink.js** offers essential features for creating exceptional music bots:
27
281. **Seamless Communication:** Developed for Lavalink clients, it ensures an uninterrupted musical experience. 🎧
29
302. **Full TypeScript Support:** Enjoy complete TypeScript support to enhance your productivity and creativity. 💻
31
323. **Active Community:** Be part of a community of passionate developers and benefit from our active support system. Our project is not just about minimizing package size but maximizing its quality and potential for developers. 🤝
33
34## Documentation
35
36For comprehensive documentation and more examples, visit [moonlink.js.org](https://moonlink.js.org). 📖
37
38## Installation
39
40```bash
41npm install moonlink.js
42yarn add moonlink.js
43pnpm install moonlink.js
44bun install moonlink.js
45```
46
47## How to Use
48
49```javascript
50// Creating an instance of the Discord.js clien
51const client = new Client({
52 intents: [
53 GatewayIntentBits.Guilds,
54 GatewayIntentBits.GuildMessages,
55 GatewayIntentBits.GuildVoiceStates
56 ]
57});
58
59// Configuring the Moonlink.js package
60client.moon = new MoonlinkManager(
61 [
62 {
63 host: "localhost",
64 port: 2333,
65 secure: true,
66 password: "password"
67 }
68 ],
69 {
70 /* Options */
71 },
72 (guild, sPayload) => {
73 // Sending payload information to the server
74 client.guilds.cache.get(guild).shard.send(JSON.parse(sPayload));
75 }
76);
77
78// Event: Node created
79client.moon.on("nodeCreate", node => {
80 console.log(`${node.host} was connected, and the magic is in the air`);
81});
82
83// Event: Track start
84client.moon.on("trackStart", async (player, track) => {
85 // Sending a message when the track starts playing
86 client.channels.cache
87 .get(player.textChannel)
88 .send(`${track.title} is playing now, bringing holiday joy`);
89});
90
91// Event: Track end
92client.moon.on("trackEnd", async (player, track) => {
93 // Sending a message when the track finishes playing
94 client.channels.cache
95 .get(player.textChannel)
96 .send(`The track is over, but the magic continues`);
97});
98
99// Event: Ready
100client.on("ready", () => {
101 // Initializing the Moonlink.js package with the client's user ID
102 client.moon.init(client.user.id);
103});
104
105// Event: Raw data
106client.on("raw", data => {
107 // Updating the Moonlink.js package with the necessary data
108 client.moon.packetUpdate(data);
109});
110
111// Event: Interaction created
112client.on("interactionCreate", async interaction => {
113 if (!interaction.isChatInputCommand()) return;
114 let commandName = interaction.commandName;
115 if (commandName === "play") {
116 if (!interaction.member.voice.channel) {
117 // Responding with a message if the user is not in a voice channel
118 return interaction.reply({
119 content: `You are not in a voice channel`,
120 ephemeral: true
121 });
122 }
123
124 let query = interaction.options.getString("query");
125 let player = client.moon.players.create({
126 guildId: interaction.guild.id,
127 voiceChannel: interaction.member.voice.channel.id,
128 textChannel: interaction.channel.id,
129 autoPlay: true
130 });
131
132 if (!player.connected) {
133 // Connecting to the voice channel if not already connected
134 player.connect({
135 setDeaf: true,
136 setMute: false
137 });
138 }
139
140 let res = await client.moon.search({
141 query,
142 source: "youtube",
143 requester: interaction.user.id
144 });
145
146 if (res.loadType === "loadfailed") {
147 // Responding with an error message if loading fails
148 return interaction.reply({
149 content: `:x: Load failed - the system is not cooperating.`
150 });
151 } else if (res.loadType === "empty") {
152 // Responding with a message if the search returns no results
153 return interaction.reply({
154 content: `:x: No matches found!`
155 });
156 }
157
158 if (res.loadType === "playlist") {
159 interaction.reply({
160 content: `${res.playlistInfo.name} This playlist has been added to the waiting list, spreading joy`
161 });
162
163 for (const track of res.tracks) {
164 // Adding tracks to the queue if it's a playlist
165 player.queue.add(track);
166 }
167 } else {
168 player.queue.add(res.tracks[0]);
169 interaction.reply({
170 content: `${res.tracks[0].title} was added to the waiting list`
171 });
172 }
173
174 if (!player.playing) {
175 // Starting playback if not already playing
176 player.play();
177 }
178});
179
180// Logging in with the Discord token
181client.login(process.env["DISCORD_TOKEN"]);
182```
183
184## Contributors
185
186We would like to express our gratitude to the amazing individuals who contributed to this project. Their hard work and dedication have been instrumental in making it a success. 🎉
187
1881. **1Lucas1apk** - Lead Developer, responsible for project architecture and key feature implementation. 🚀
189
1902. **MotoG.js** - Project Ideator and Designer, contributing to the concept and visual design. 🎨
191
1923. **WilsontheWolf** - Contributed to the track position logic in real time, rather than just receiving the payload from lavalink.
193
1944. **PiscesXD** - First sponsor and contributed to making the shuffle method reversible, and autoLeave.
195
1965. **Suryansh** - Second contributor and helped discover bugs 🌷
197
198Other contributors: Nah, ItzGG, SuperPlayerBot, ddemile, Tasty-Kiwi, rrm, WilsontheWolf, Aertic, 'Forster, Fireball, Ghos't, loulou310 - Xotak
199
200We sincerely thank all the contributors mentioned above and everyone who contributed to this project in any way. Your support is truly appreciated. 🙏
201
202## Final Thanks
203
204Thank you to everyone who contributed to the growth of moonlink.js, reporting bugs, installing the package and everyone else's patience, I apologize for any time I wasn't able to help someone
205
206have a great day :)
207
208## License
209
210This project is licensed under the [Open Software License ("OSL") v. 3.0](LICENSE) - see the [LICENSE](LICENSE) file for details.
211
212## Support
213
214Join our Discord server at [Moonlink.js - Imagine a Music Bot](https://discord.com/invite/xQq2A8vku3) to connect with other users, ask questions, and participate in discussions. 🤝
215
216For any inquiries or assistance, we're here to help! 🌟