- Notifications
You must be signed in to change notification settings - Fork7
Riffy is a pro lavalink client. It is designed to be simple and easy to use, with a focus on stability and more features.
License
riffy-team/riffy
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A lavalink client for Node.JS, designed to be simple and easy to use. Compatible with all Discord libraries (discord.js, Eris, etc.).
npm install riffy
- Supports versions 3 and 4 of the Lavalink protocols.
- Autoplay support for YouTube, SoundCloud, and Spotify.
- Compatible with all Discord libraries (discord.js, Eris, etc.).
- Works with all Lavalink filters.
First things first, you need to have a Lavalink node running. You can download the latest version of Lavalink fromhere, or you can usethis nodes for free.
Note
This project usesMessageContent
intent, so make sure to enable it in your application settings.
We are usingdiscord.js for this example, but you can use any Discord library you prefer.
Import theRiffy
class from theriffy
package.
// For CommonJSconst{ Riffy}=require("riffy");// For ES6import{Riffy}from"riffy";
Below is an example of a basic Discord music bot using Discord.js and Riffy. (Lavalink V4)
// index.jsconst{ Client, GatewayDispatchEvents}=require("discord.js");const{ Riffy}=require("riffy");constclient=newClient({intents:["Guilds","GuildMessages","GuildVoiceStates","GuildMessageReactions","MessageContent","DirectMessages",],});constnodes=[{host:"localhost",password:"youshallnotpass",port:2333,secure:false,},];client.riffy=newRiffy(client,nodes,{send:(payload)=>{constguild=client.guilds.cache.get(payload.d.guild_id);if(guild)guild.shard.send(payload);},defaultSearchPlatform:"ytmsearch",restVersion:"v4",// Or "v3" based on your Lavalink version.});client.on("ready",()=>{client.riffy.init(client.user.id);console.log(`Logged in as${client.user.tag}`);});client.on("messageCreate",async(message)=>{if(!message.content.startsWith("!")||message.author.bot)return;constargs=message.content.slice(1).trim().split(" ");constcommand=args.shift().toLowerCase();if(command==="play"){constquery=args.join(" ");// Create a player.constplayer=client.riffy.createConnection({guildId:message.guild.id,voiceChannel:message.member.voice.channel.id,textChannel:message.channel.id,deaf:true,});constresolve=awaitclient.riffy.resolve({query:query,requester:message.author,});const{ loadType, tracks, playlistInfo}=resolve;/** * Important: If you are using Lavalink V3, here are the changes you need to make: * * 1. Replace "playlist" with "PLAYLIST_LOADED" * 2. Replace "search" with "SEARCH_RESULT" * 3. Replace "track" with "TRACK_LOADED" */if(loadType==="playlist"){for(consttrackofresolve.tracks){track.info.requester=message.author;player.queue.add(track);}message.channel.send(`Added: \`${tracks.length} tracks\` from \`${playlistInfo.name}\``);if(!player.playing&&!player.paused)returnplayer.play();}elseif(loadType==="search"||loadType==="track"){consttrack=tracks.shift();track.info.requester=message.author;player.queue.add(track);message.channel.send(`Added: \`${track.info.title}\``);if(!player.playing&&!player.paused)returnplayer.play();}else{returnmessage.channel.send("There are no results found.");}}});// This will send log when the lavalink node is connected.client.riffy.on("nodeConnect",(node)=>{console.log(`Node "${node.name}" connected.`);});// This will send log when the lavalink node faced an error.client.riffy.on("nodeError",(node,error)=>{console.log(`Node "${node.name}" encountered an error:${error.message}.`);});// This is the event handler for track start.client.riffy.on("trackStart",async(player,track)=>{constchannel=client.channels.cache.get(player.textChannel);channel.send(`Now playing: \`${track.info.title}\` by \`${track.info.author}\`.`);});// This is the event handler for queue end.client.riffy.on("queueEnd",async(player)=>{constchannel=client.channels.cache.get(player.textChannel);// Set this to true if you want to enable autoplay.constautoplay=false;if(autoplay){player.autoplay(player);}else{player.destroy();channel.send("Queue has ended.");}});// This will update the voice state of the player.client.on("raw",(d)=>{if(![GatewayDispatchEvents.VoiceStateUpdate,GatewayDispatchEvents.VoiceServerUpdate,].includes(d.t))return;client.riffy.updateVoiceState(d);});client.login("Discord-Bot-Token-Here");
Now that we have created our project, we can run our bot by typing the following command in the terminal.
# node.jsnode index.js# bunbun run index.js
After running the bot, you can invite it to your server and use the!play
command to play music.
That's it! You have successfully created a discord music bot using riffy. If you have any questions, feel free to join ourdiscord server.
We have set this example by keeping in mind that you know the basics of discord.js or any other discord library you are using.
🟪 Elitex
- Github:@Elitex
- Discord: @elitex
🟥 FlameFace
- Github:@FlameFace
- Discord: @flameface
🟦 UnschooledGamer
- Github:@UnschooledGamer
- Discord: @unschooledgamer
This project is licensed under theMIT License
About
Riffy is a pro lavalink client. It is designed to be simple and easy to use, with a focus on stability and more features.