-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Next version Thanks for 4k Views for my first video
- Loading branch information
1 parent
f12d1b2
commit 7a6b539
Showing
22 changed files
with
434 additions
and
1,150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
DISCORD_TOKEN= | ||
DISCORD_PREFIX=! | ||
TOKEN="" | ||
PREFIX="!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
# Packages | ||
node_modules/ | ||
package-lock.json | ||
yarn.lock | ||
|
||
# Envronmental Storage | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
# Important Biggest Update Comming soon | ||
> And yes a updated tutorial :> without using the api | ||
# Discord Music bot | ||
> Very simple discord music bot with the discord.js with Song Name playing. It can able to play music with song name. | ||
## Tutorial | ||
|
||
Video tutorial click [here](https://youtu.be/wWVXN4mIgz8). [Support in Discord](https://sudhanplayz.live/discord) | ||
## IMPORTANT | ||
Please use this [SudhanPlayz/Discord-MusicBot/tree/v1.0.0](https://github.com/SudhanPlayz/Discord-MusicBot/tree/v1.0.0) | ||
# Advanced Discord Music Bot | ||
Thanks for 4k Views! I made this for you all! | ||
|
||
<div align="center"><img src="./assets/banner.gif"></div> | ||
|
||
## Tutorial | ||
Soon | ||
|
||
## Screenshots | ||
|
||
<div align="left"><img src="https://pika-pika.is-inside.me/zJduq9Gn.png"></div><div align="center"><img src="https://pika-pika.is-inside.me/9ufBoGDH.png"></div><div align="right"><img src="https://pika-pika.is-inside.me/8QkGROJv.png"></div> | ||
|
||
## Run the projects | ||
Soon | ||
|
||
## Contributors | ||
|
||
<a href="https://github.com/SudhanPlayz/Discord-MusicBot/graphs/contributors"> | ||
<img src="https://contributors-img.web.app/image?repo=SudhanPlayz/Discord-MusicBot" /> | ||
</a> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const { MessageEmbed } = require('discord.js') | ||
|
||
module.exports = { | ||
info: { | ||
name: "help", | ||
description: "To show all commands", | ||
usage: "[command]", | ||
aliases: ["commands", "help me", "pls help"] | ||
}, | ||
|
||
run: async function(client, message, args){ | ||
var allcmds = ""; | ||
|
||
client.commands.forEach(cmd => { | ||
let cmdinfo = cmd.info | ||
allcmds+="``"+client.config.prefix+cmdinfo.name+" "+cmdinfo.usage+"`` ~ "+cmdinfo.description+"\n" | ||
}) | ||
|
||
let embed = new MessageEmbed() | ||
.setAuthor("Commands of "+client.user.username, client.user.displayAvatarURL()) | ||
.setColor("BLUE") | ||
.setDescription(allcmds) | ||
.setFooter(`To get info of each command you can do ${client.config.prefix}help [command] | Hander by ItzCutePikachu#2006`) | ||
|
||
if(!args[0])return message.channel.send(embed) | ||
else { | ||
let cmd = args[0] | ||
let command = client.commands.get(cmd) | ||
if(!command)command = client.commands.find(x => x.info.aliases.includes(cmd)) | ||
if(!command)return message.channel.send("Unknown Command") | ||
let commandinfo = new MessageEmbed() | ||
.setTitle("Command: "+command.info.name+" info") | ||
.setColor("YELLOW") | ||
.setDescription(` | ||
Name: ${command.info.name} | ||
Description: ${command.info.description} | ||
Usage: \`\`${client.config.prefix}${command.info.name} ${command.info.usage}\`\` | ||
Aliases: ${command.info.aliases.join(", ")} | ||
`) | ||
message.channel.send(commandinfo) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const { MessageEmbed } = require("discord.js"); | ||
const sendError = require("../util/error") | ||
|
||
module.exports = { | ||
info: { | ||
name: "nowplaying", | ||
description: "To show the music which is currently playing in this server", | ||
usage: "", | ||
aliases: ["np"], | ||
}, | ||
|
||
run: async function (client, message, args) { | ||
const serverQueue = message.client.queue.get(message.guild.id); | ||
if (!serverQueue) return sendError("There is nothing playing in this server.", message.channel); | ||
let song = serverQueue.songs[0] | ||
let thing = new MessageEmbed() | ||
.setAuthor("Now Playing", song.req.displayAvatarURL({ dynamic: true })) | ||
.setThumbnail(song.img) | ||
.setColor("BLUE") | ||
.addField("Name", song.title, true) | ||
.addField("Duration", song.duration, true) | ||
.addField("Requested by", song.req.tag, true) | ||
.setFooter(`Views: ${song.views} | ${song.ago}`) | ||
return message.channel.send(thing) | ||
}, | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,25 @@ | ||
exports.run = (client, message, args) => { | ||
const serverQueue = message.client.queue.get(message.guild.id); | ||
if (serverQueue && serverQueue.playing) { | ||
serverQueue.playing = false; | ||
serverQueue.connection.dispatcher.pause(); | ||
return message.channel.send("⏸ Paused the music for you!"); | ||
} | ||
return message.channel.send("There is nothing playing."); | ||
}; | ||
const { MessageEmbed } = require("discord.js"); | ||
const sendError = require("../util/error"); | ||
|
||
module.exports = { | ||
info: { | ||
name: "pause", | ||
description: "To pause the current music in the server", | ||
usage: "", | ||
aliases: [""], | ||
}, | ||
|
||
run: async function (client, message, args) { | ||
const serverQueue = message.client.queue.get(message.guild.id); | ||
if (serverQueue && serverQueue.playing) { | ||
serverQueue.playing = false; | ||
serverQueue.connection.dispatcher.pause(); | ||
let xd = new MessageEmbed() | ||
.setDescription("⏸ Paused the music for you!") | ||
.setColor("YELLOW") | ||
.setTitle("Music has been paused!") | ||
return message.channel.send(xd); | ||
} | ||
return sendError("There is nothing playing in this server.", message.channel); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,106 @@ | ||
const { Util } = require("discord.js"); | ||
const ytdl = require("ytdl-core"); | ||
const ytSearch = require("../utils/ytSearch"); | ||
|
||
exports.run = async (client, message, args) => { | ||
const { channel } = message.member.voice; | ||
if (!channel) | ||
return message.channel.send( | ||
"I'm sorry but you need to be in a voice channel to play music!" | ||
); | ||
const permissions = channel.permissionsFor(message.client.user); | ||
if (!permissions.has("CONNECT")) | ||
return message.channel.send( | ||
"I cannot connect to your voice channel, make sure I have the proper permissions!" | ||
); | ||
if (!permissions.has("SPEAK")) | ||
return message.channel.send( | ||
"I cannot speak in this voice channel, make sure I have the proper permissions!" | ||
); | ||
const searchString = args.join(" "); | ||
if (!searchString) | ||
return message.channel.send("You didn't provide anything to play"); | ||
const serverQueue = message.client.queue.get(message.guild.id); | ||
|
||
const videos = await ytSearch(searchString, 1); | ||
if (!videos || !videos.length) { | ||
return message.channel.send("No videos found with that keyword!"); | ||
} | ||
|
||
// old method, doesn't work most of the time | ||
// const song = { | ||
// id: firstVideo.videoId, | ||
// url: firstVideo.url, | ||
// title: Util.escapeMarkdown(firstVideo.title), | ||
// author: firstVideo.author, | ||
// duration: firstVideo.duration, | ||
// durationSeconds: firstVideo.durationSeconds, | ||
// ago: firstVideo.ago, | ||
// views: firstVideo.views, | ||
// }; | ||
|
||
const firstVideo = videos[0].full ? videos[0] : videos[0].fetch(); | ||
|
||
const song = { | ||
id: firstVideo.id, | ||
url: `https://youtube.com/watch?v=${firstVideo.id}`, | ||
title: Util.escapeMarkdown(firstVideo.title), | ||
author: firstVideo.channel.title, | ||
duration: firstVideo.duration, | ||
durationSeconds: firstVideo.durationSeconds, | ||
}; | ||
|
||
if (serverQueue) { | ||
serverQueue.songs.push(song); | ||
console.log(serverQueue.songs); | ||
return message.channel.send( | ||
`✅ **${song.title}** has been added to the queue!` | ||
); | ||
} | ||
|
||
const queueConstruct = { | ||
textChannel: message.channel, | ||
voiceChannel: channel, | ||
connection: null, | ||
songs: [], | ||
volume: 2, | ||
playing: true, | ||
}; | ||
message.client.queue.set(message.guild.id, queueConstruct); | ||
queueConstruct.songs.push(song); | ||
|
||
const play = async (song) => { | ||
const queue = message.client.queue.get(message.guild.id); | ||
if (!song) { | ||
queue.voiceChannel.leave(); | ||
message.client.queue.delete(message.guild.id); | ||
return; | ||
} | ||
|
||
const dispatcher = queue.connection | ||
.play(ytdl(song.url)) | ||
.on("finish", () => { | ||
queue.songs.shift(); | ||
play(queue.songs[0]); | ||
}) | ||
.on("error", (error) => console.error(error)); | ||
dispatcher.setVolumeLogarithmic(queue.volume / 5); | ||
queue.textChannel.send(`🎶 Start playing: **${song.title}**`); | ||
}; | ||
|
||
try { | ||
const connection = await channel.join(); | ||
queueConstruct.connection = connection; | ||
play(queueConstruct.songs[0]); | ||
} catch (error) { | ||
console.error(`I could not join the voice channel: ${error}`); | ||
message.client.queue.delete(message.guild.id); | ||
await channel.leave(); | ||
return message.channel.send(`I could not join the voice channel: ${error}`); | ||
} | ||
}; | ||
const { Util, MessageEmbed } = require("discord.js"); | ||
const ytdl = require("ytdl-core"); | ||
const yts = require("yt-search"); | ||
const sendError = require("../util/error") | ||
|
||
module.exports = { | ||
info: { | ||
name: "play", | ||
description: "To play songs :D", | ||
usage: "<song_name>", | ||
aliases: ["p"], | ||
}, | ||
|
||
run: async function (client, message, args) { | ||
const channel = message.member.voice.channel; | ||
if (!channel)return sendError("I'm sorry but you need to be in a voice channel to play music!", message.channel); | ||
|
||
const permissions = channel.permissionsFor(message.client.user); | ||
if (!permissions.has("CONNECT"))return sendError("I cannot connect to your voice channel, make sure I have the proper permissions!", message.channel); | ||
if (!permissions.has("SPEAK"))return sendError("I cannot speak in this voice channel, make sure I have the proper permissions!", message.channel); | ||
|
||
var searchString = args.join(" "); | ||
if (!searchString)return sendError("You didn't poivide want i want to play", message.channel); | ||
|
||
var serverQueue = message.client.queue.get(message.guild.id); | ||
|
||
var searched = await yts.search(searchString) | ||
if(searched.videos.length === 0)return sendError("Looks like i was unable to find the song on YouTube", message.channel) | ||
var songInfo = searched.videos[0] | ||
|
||
const song = { | ||
id: songInfo.videoId, | ||
title: Util.escapeMarkdown(songInfo.title), | ||
views: String(songInfo.views).padStart(10, ' '), | ||
url: songInfo.url, | ||
ago: songInfo.ago, | ||
duration: songInfo.duration.toString(), | ||
img: songInfo.image, | ||
req: message.author | ||
}; | ||
|
||
if (serverQueue) { | ||
serverQueue.songs.push(song); | ||
let thing = new MessageEmbed() | ||
.setAuthor("Song has been added to queue", song.req.displayAvatarURL({ dynamic: true })) | ||
.setThumbnail(song.img) | ||
.setColor("YELLOW") | ||
.addField("Name", song.title, true) | ||
.addField("Duration", song.duration, true) | ||
.addField("Requested by", song.req.tag, true) | ||
.setFooter(`Views: ${song.views} | ${song.ago}`) | ||
return message.channel.send(thing); | ||
} | ||
|
||
const queueConstruct = { | ||
textChannel: message.channel, | ||
voiceChannel: channel, | ||
connection: null, | ||
songs: [], | ||
volume: 2, | ||
playing: true, | ||
}; | ||
message.client.queue.set(message.guild.id, queueConstruct); | ||
queueConstruct.songs.push(song); | ||
|
||
const play = async (song) => { | ||
const queue = message.client.queue.get(message.guild.id); | ||
if (!song) { | ||
sendError("Leaving the voice channel because I think there are no songs in the queue. If you like the bot stay 24/7 in voice channel go to `commands/play.js` and remove the line number 61\n\nThank you for using my code! [GitHub](https://github.com/SudhanPlayz/Discord-MusicBot)", message.channel) | ||
queue.voiceChannel.leave();//If you want your bot stay in vc 24/7 remove this line :D | ||
message.client.queue.delete(message.guild.id); | ||
return; | ||
} | ||
|
||
const dispatcher = queue.connection | ||
.play(ytdl(song.url)) | ||
.on("finish", () => { | ||
queue.songs.shift(); | ||
play(queue.songs[0]); | ||
}) | ||
.on("error", (error) => console.error(error)); | ||
dispatcher.setVolumeLogarithmic(queue.volume / 5); | ||
let thing = new MessageEmbed() | ||
.setAuthor("Started Playing Music!", song.req.displayAvatarURL({ dynamic: true })) | ||
.setThumbnail(song.img) | ||
.setColor("BLUE") | ||
.addField("Name", song.title, true) | ||
.addField("Duration", song.duration, true) | ||
.addField("Requested by", song.req.tag, true) | ||
.setFooter(`Views: ${song.views} | Ago: ${song.ago}`) | ||
queue.textChannel.send(thing); | ||
}; | ||
|
||
try { | ||
const connection = await channel.join(); | ||
queueConstruct.connection = connection; | ||
channel.guild.voice.setSelfDeaf(true) | ||
play(queueConstruct.songs[0]); | ||
} catch (error) { | ||
console.error(`I could not join the voice channel: ${error}`); | ||
message.client.queue.delete(message.guild.id); | ||
await channel.leave(); | ||
return sendError(`I could not join the voice channel: ${error}`, message.channel); | ||
} | ||
} | ||
}; |
Oops, something went wrong.