Skip to content
This repository has been archived by the owner on Jun 18, 2022. It is now read-only.

Commit

Permalink
add distube and more
Browse files Browse the repository at this point in the history
  • Loading branch information
vachanmn123 committed Oct 30, 2021
1 parent 5181383 commit 918c29b
Show file tree
Hide file tree
Showing 19 changed files with 4,987 additions and 332 deletions.
117 changes: 3 additions & 114 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,114 +1,3 @@
<h1 align="center">Welcome to NamVr Discord Bot Template 👋</h1>
<p>
<img alt="Version" src="https://img.shields.io/badge/version-v3.0-blue.svg?cacheSeconds=2592000" />
<a href="https://github.com/NamVr/DiscordBot-Template#readme" target="_blank">
<img alt="Documentation" src="https://img.shields.io/badge/documentation-yes-brightgreen.svg" />
</a>
<a href="https://github.com/NamVr/DiscordBot-Template/graphs/commit-activity" target="_blank">
<img alt="Maintenance" src="https://img.shields.io/badge/Maintained%3F-yes-green.svg" />
</a>
<a href="https://twitter.com/namanvrati" target="_blank">
<img alt="Twitter: namanvrati" src="https://img.shields.io/twitter/follow/namanvrati.svg?style=social" />
</a>
</p>

> An **open source** `discord.js` bot template which is based on official [discord.js guide](https://discordjs.guide/) to get started on making your very personal discord bot!
### 🏠 [Homepage](https://github.com/NamVr/DiscordBot-Template#readme)

## Introduction

`NamVr` Discord Bot Template is an open source discord.js based bot template to get started on a new bot project. It is classic javascript template, not requiring any external dependencies unlike other famous frameworks. (This is not a framework!)
You can scale any kind of bot project using this template. (single server based or multiple server based) It all depends on your creativity!

### Features:

This template comes in with many in-built useful and flexible features, such as

#### **Dynamic Command Handler:**

- My template comes in with a dynamic command handler! Using the command handler, you don't need to indulge in main bot files to create your very own command!
- You can simply make command groups (categorized as folders) in the [commands](https://github.com/NamVr/DiscordBot-Template/tree/master/commands/) folder.
- Your JavaScript commands goes inside respective category folders. A sample command is provided as [ping](https://github.com/NamVr/DiscordBot-Template/blob/master/commands/misc/ping.js) command. You can use the same skeleton for all commands you want!

#### **Dynamic Event Handler:**

- All events goes inside the [events](https://github.com/NamVr/DiscordBot-Template/blob/master/events/) folder. You don't need to use `client.on()` in the main `bot.js` file to handle events.
- Using simple skeleton code for events, you can make any amount of events in the events folder using the event handler.

#### **Dynamic Trigger Handler:**

- Triggers occur when a specific "phrase" is said in a message content. For example, if you want your bot to react with :heart: when someone say `welcome` in their message, you can do that with this trigger handler!
- Trigger Handler also has the same skeleton structure as of command handler. The trigger handler is associated with the [triggers](https://github.com/NamVr/DiscordBot-Template/tree/master/triggers/) folder. There are trigger categories, like [reactions](https://github.com/NamVr/DiscordBot-Template/tree/master/triggers/reactions) folder, in the trigger folder.
- A sample trigger command is given in the [`hello.js`](https://github.com/NamVr/DiscordBot-Template/tree/master/triggers/reactions/hello.js) trigger file.

#### **[NEW] Dynamic Slash Command Handler:**

- My template comes with a dynamic slash command handler with very easy to customize and make slash commands.
- The commands, in the slashCommands folder, receive an [`CommandInteraction`](https://discord.js.org/#/docs/main/stable/class/CommandInteraction) object. You can see the [documentation of discord.js](https://discord.js.org/#/docs/main/stable/class/CommandInteraction) for all the properties and methods available.
- **IMPORTANT:** In the template, we are sending the slash commands to discord to be registered only to 1 guild. That is because their are 2 types of slash commands, guild and global. Guild commands are restricted to 1 guild but whenever you update them, they take effect immediately, whereas global commands take upto 1 hour to take effect. So use guild commands in development and global commands for production.

#### **[NEW] Dynamic Buttons Interaction Handler:**

- This template comes with a dynamic button interaction handler to receive and process button interactions.
- Buttons can be classified in two category folders.

#### **[NEW] Dynamic Context Menu Handler:**

- All new addition to discord API is context menus! You can right click a user or message -> Apps to find these options!
- This template will register all your context menu options and dynamically interact with them! Worth a try.

#### **Highly Customizable:**

Using the template is so easy and fun, you would know. As the template does not rely on any external dependencies and written in javascript, it is highly customizable to any extend. There's no end to your creativity!

#### **Open source and self-hosted:**

> It's yours, you have full control.
## Install

```sh
npm install
```

## Run tests

```sh
npm run test
```

## Support & Documentation

I'm working to make it more professional and easy to use for everyone. There will be a documentation out very soon.

## Authors

👤 **Naman Vrati**

- Website: https://namanvrati.cf/
- Twitter: [@namanvrati](https://twitter.com/namanvrati)
- Github: [@NamVr](https://github.com/NamVr)
- LinkedIn: [@namanvrati](https://linkedin.com/in/namanvrati)

👤 **Krish Garg**

- Website: https://krishgarg.ga/
- Twitter: [@KrishGa95586696](https://twitter.com/KrishGa95586696)
- Github: [@KrishGarg](https://github.com/KrishGarg)

## 🤝 Contributing

Contributions, issues and feature requests are welcome!<br />Feel free to check [issues page](https://github.com/NamVr/DiscordBot-Template/issues). You can also take a look at the [contributing guide](https://github.com/NamVr/DiscordBot-Template/blob/master/CONTRIBUTING.md).

## Show your support

Give a ⭐️ if this project helped you! Star-ring the project gives me encouragement to continue it.
You can also [sponsor](https://ko-fi.com/namanvrati) the project and get listed as a contributer! Thanks a lot.

## 📝 License

Copyright © 2021 [Naman Vrati](https://github.com/NamVr).<br />
This project is [ISC](https://github.com/NamVr/DiscordBot-Template/blob/master/LICENSE) licensed.

---
<h1> IvyMusic </h1>
<h2> The Project </h1>
<p> I will do this later I promise </p>
43 changes: 42 additions & 1 deletion bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ const { Client, Collection, Intents } = require("discord.js");
const { REST } = require("@discordjs/rest");
const { Routes } = require("discord-api-types/v9");
const { token, client_id, test_guild_id } = require("./config.json");
const DisTube = require('distube')
const SoundCloudPlugin = require('@distube/soundcloud')
const SpotifyPlugin = require('@distube/spotify')

/**
* From v13, specifying the intents is compulsory.
* @type {Object}
* @description Main Application Client */

const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_VOICE_STATES],
});


/**********************************************************************/
// Below we will be making an event handler!

Expand Down Expand Up @@ -56,6 +60,16 @@ client.selectCommands = new Collection();
client.contextCommands = new Collection();
client.cooldowns = new Collection();
client.triggers = new Collection();
client.distube = new DisTube.default(client, {
searchSongs: 1,
searchCooldown: 30,
leaveOnEmpty: true,
emptyCooldown: 0,
leaveOnFinish: true,
leaveOnStop: true,
plugins: [new SoundCloudPlugin.default(), new SpotifyPlugin.default()],
})


/**********************************************************************/
// Registration of Message-Based Commands
Expand Down Expand Up @@ -227,6 +241,33 @@ for (const folder of triggerFolders) {
}
}

// Distube initialization.
const status = queue => `Volume: \`${queue.volume}%\` | Filter: \`${queue.filters.join(", ") || "Off"}\` | Loop: \`${queue.repeatMode ? queue.repeatMode === 2 ? "All Queue" : "This Song" : "Off"}\` | Autoplay: \`${queue.autoplay ? "On" : "Off"}\``
client.distube
.on("playSong", (queue, song) => queue.textChannel.send(
`Playing \`${song.name}\` - \`${song.formattedDuration}\`\nRequested by: ${song.user}\n${status(queue)}`
))
.on("addSong", (queue, song) => queue.textChannel.send(
`Added ${song.name} - \`${song.formattedDuration}\` to the queue by ${song.user}`
))
.on("addList", (queue, playlist) => queue.textChannel.send(
`Added \`${playlist.name}\` playlist (${playlist.songs.length} songs) to queue\n${status(queue)}`
))
// DisTubeOptions.searchSongs = true
.on("searchResult", (message, result) => {
let i = 0
message.channel.send(`**Choose an option from below**\n${result.map(song => `**${++i}**. ${song.name} - \`${song.formattedDuration}\``).join("\n")}\n*Enter anything else or wait 60 seconds to cancel*`)
})
// DisTubeOptions.searchSongs = true
.on("searchCancel", message => message.channel.send(`Searching canceled`))
.on("error", (channel, e) => {
channel.send(`An error encountered: ${e}`)
console.error(e)
})
.on("empty", channel => channel.send("Voice channel is empty! Leaving the channel..."))
.on("searchNoResult", message => message.channel.send(`No result found!`))
.on("finish", queue => queue.textChannel.send("Finished!"))

// Login into your client application with bot's token.

client.login(token);
24 changes: 24 additions & 0 deletions commands/music/autoplay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
name: "autoplay",
description: "Turn on/off Autoplay",
usage: "autoplay",
guildOnly: true,
/**
* @description Executes when the command is called by command handler.
* @author Vachan MN
* @param {Object} message The Message Object of the command.
* @param {String[]} args The Message Content of the received message seperated by spaces (' ') in an array, this excludes prefix and command/alias itself.
*/

execute(message, args) {
const client = message.client;
const queue = client.distube.getQueue(message)
if (!queue) return message.channel.send(`There is nothing in the queue right now!`)
try {
const autoplay = queue.toggleAutoplay()
message.channel.send(`AutoPlay: \`${autoplay ? "On" : "Off"}\``)
} catch (e) {
message.channel.send(`${e}`)
}
},
};
21 changes: 21 additions & 0 deletions commands/music/filters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
name: "filters",
description: "Add filters to the playing song",
usage: "filters <filter>",
guildOnly: true,
/**
* @description Executes when the command is called by command handler.
* @author Vachan MN
* @param {Object} message The Message Object of the command.
* @param {String[]} args The Message Content of the received message seperated by spaces (' ') in an array, this excludes prefix and command/alias itself.
*/

execute(message, args) {
const queue = message.client.distube.getQueue(message)
if (!queue) return message.channel.send(`There is nothing in the queue right now!`)
if (args[0] === "off" && queue.filters?.length) queue.setFilter(false)
else if (Object.keys(message.client.distube.filters).includes(args[0])) queue.setFilter(args[0])
else if (args[0]) return message.channel.send(`Not a valid filter`)
message.channel.send(`Current Queue Filter: \`${queue.filters.join(", ") || "Off"}\``)
},
};
24 changes: 24 additions & 0 deletions commands/music/pause.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
name: "pause",
description: "pause the playing song",
usage: "pause",
guildOnly: true,
/**
* @description Executes when the command is called by command handler.
* @author Vachan MN
* @param {Object} message The Message Object of the command.
* @param {String[]} args The Message Content of the received message seperated by spaces (' ') in an array, this excludes prefix and command/alias itself.
*/

execute(message, args) {
const client = message.client;
const queue = client.distube.getQueue(message)
if (!queue) return message.channel.send(`There is nothing in the queue right now!`)
if (queue.pause) {
queue.resume()
return message.channel.send("Resumed the song for you :)")
}
queue.pause()
message.channel.send("Paused the song for you :)")
},
};
27 changes: 27 additions & 0 deletions commands/music/play.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const DisTube = require('distube')

module.exports = {
name: "play",
description: "Play a song",
usage: "play <song name>",
guildOnly: true,

/**
* @description Executes when the command is called by command handler.
* @author Vachan MN
* @param {Object} message The Message Object of the command.
* @param {String[]} args The Message Content of the received message seperated by spaces (' ') in an array, this excludes prefix and command/alias itself.
*/

execute(message, args) {
const distube = message.client.distube
searchString = args.join(' ');
if (!message.member.voice.channel) return message.reply('YOU ARENT IN A VC!')
if (!searchString) return message.reply('Please enter the search string or url')
try {
distube.play(message, args.join(' '))
} catch (e) {
return message.reply(e)
}
},
};
24 changes: 24 additions & 0 deletions commands/music/previous.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
name: "previous",
description: "Plays the previous song",
usage: "previous",
guildOnly: true,
/**
* @description Executes when the command is called by command handler.
* @author Vachan MN
* @param {Object} message The Message Object of the command.
* @param {String[]} args The Message Content of the received message seperated by spaces (' ') in an array, this excludes prefix and command/alias itself.
*/

execute(message, args) {
const client = message.client;
const queue = client.distube.getQueue(message)
if (!queue) return message.channel.send(`There is nothing in the queue right now!`)
try {
const song = queue.previous()
message.channel.send(`Now playing:\n${song.name}`)
} catch (e) {
message.channel.send(`${e}`)
}
},
};
19 changes: 19 additions & 0 deletions commands/music/queue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
name: "queue",
description: "show the queue",
usage: "queue",
guildOnly: true,
/**
* @description Executes when the command is called by command handler.
* @author Vachan MN
* @param {Object} message The Message Object of the command.
* @param {String[]} args The Message Content of the received message seperated by spaces (' ') in an array, this excludes prefix and command/alias itself.
*/

execute(message, args) {
const queue = message.client.distube.getQueue(message)
if (!queue) return message.channel.send(`There is nothing playing!`)
const q = queue.songs.map((song, i) => `${i === 0 ? "Playing:" : `${i}.`} ${song.name} - \`${song.formattedDuration}\``).join("\n")
message.channel.send(`**Server Queue**\n${q}`)
},
};
34 changes: 34 additions & 0 deletions commands/music/repeat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module.exports = {
name: "repeat",
description: "Select the repeat pattern",
usage: "repeat <off/song/queue>",
guildOnly: true,
aliases: ["loop"],
/**
* @description Executes when the command is called by command handler.
* @author Vachan MN
* @param {Object} message The Message Object of the command.
* @param {String[]} args The Message Content of the received message seperated by spaces (' ') in an array, this excludes prefix and command/alias itself.
*/

execute(message, args) {
const client = message.client;
const queue = client.distube.getQueue(message)
if (!queue) return message.channel.send(`There is nothing playing!`)
let mode = null
switch (args[0]) {
case "off":
mode = 0
break
case "song":
mode = 1
break
case "queue":
mode = 2
break
}
mode = queue.setRepeatMode(mode)
mode = mode ? mode === 2 ? "Repeat queue" : "Repeat song" : "Off"
message.channel.send(`Set repeat mode to \`${mode}\``)
},
};
20 changes: 20 additions & 0 deletions commands/music/resume.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
name: "resume",
description: "Resume the paused song",
usage: "resume",
guildOnly: true,
/**
* @description Executes when the command is called by command handler.
* @author Vachan MN
* @param {Object} message The Message Object of the command.
* @param {String[]} args The Message Content of the received message seperated by spaces (' ') in an array, this excludes prefix and command/alias itself.
*/

execute(message, args) {
const client = message.client;
const queue = client.distube.getQueue(message)
if (!queue) return message.channel.send(`There is nothing in the queue right now!`)
queue.resume()
message.channel.send("Resumed the song for you :)")
},
};
Loading

0 comments on commit 918c29b

Please sign in to comment.