Skip to content

Commit

Permalink
sudhan and me did something
Browse files Browse the repository at this point in the history
  • Loading branch information
DarrenOfficial committed Nov 5, 2021
1 parent 7516184 commit 0906fbd
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 65 deletions.
28 changes: 28 additions & 0 deletions commands/slash/247.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const { MessageEmbed } = require("discord.js");
const SlashCommand = require("../../lib/SlashCommand");

const command = new SlashCommand()
.setName("247")
.setDescription("toggles 24/7")
.setRun(async (client, interaction, options) => {
const player = interaction.client.manager.players.get(interaction.guild.id);
if (!player) {
return interaction.reply({
embeds: [client.ErrorEmbed("There's nothing to play 24/7!")],
});
} else if (player.twentyFourSeven) {
player.twentyFourSeven = false;
const embed = client.Embed(`24/7 mode is now off.`);
return interaction.reply({ embeds: [embed] });
} else {
player.twentyFourSeven = true;
const embed = client.Embed(`24/7 mode is now on.`);
return interaction.reply({ embeds: [embed] });
}
});
module.exports = command;
// check above message, it is a little bit confusing. and erros are not handled. probably should be fixed.
// ok use catch ez kom follow meh ;_;
// the above message meaning error, if it cant find it or take too long the bot crashed
// play commanddddd, if timeout or takes 1000 years to find song it crashed
// OKIE, leave the comment here for idk
8 changes: 2 additions & 6 deletions commands/slash/disconnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@ const command = new SlashCommand()
let player = client.manager.players.get(interaction.guild.id);
if (!player)
return interaction.reply({
embeds: [
client.ErrorEmbed(
"Theres nothing to disconnect!"
),
],
embeds: [client.ErrorEmbed("Theres nothing to disconnect!")],
});

player.destroy();

interaction.reply({
embeds: [client.Embed(`Successfully left <#${channel.id}>!`)],
embeds: [client.Embed(`Disconnected!`)],
});
});

Expand Down
21 changes: 21 additions & 0 deletions commands/slash/loop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const SlashCommand = require("../../lib/SlashCommand");

const command = new SlashCommand()
.setName("loop")
.setDescription("Loop the current song")
.setRun(async (client, interaction, options) => {
let player = client.manager.players.get(interaction.guild.id);
if (!player) {
return interaction.reply({
embeds: [client.ErrorEmbed("There's nothing to be looped!")],
});
}
if (!player.loop(false)) player.loop(true);
else if (!player.loop(true)) player.loop(false);

interaction.reply({
embeds: [client.Embed(`Loop has been set to ${player.loop}`)],
});
});

module.exports = command;
41 changes: 25 additions & 16 deletions commands/slash/play.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,42 @@ const command = new SlashCommand()
if (!channel) return;

let node = await client.getLavalink(client);
if (!node)
if (!node) {
return interaction.reply({
embeds: [client.ErrorEmbed("Lavalink node is not connected")],
});
}

let query = options.getString("query", true);
let player = client.createPlayer(interaction.channel, channel);

if (player.state != "CONNECTED") await player.connect();

let res = await player.search(query, interaction.user);
await interaction.reply({ embeds: [client.Embed("Searching...")] });

let res = await player.search(query, interaction.user).catch((err) => {
client.error(err);
return {
loadType: "LOAD_FAILED",
};
});

if (res.loadType === "LOAD_FAILED") {
if (!player.queue.current) player.destroy();
return interaction.reply({
embeds: [client.ErrorEmbed("There was an error while searching")],
});
return interaction
.editReply({
embeds: [client.ErrorEmbed("There was an error while searching")],
})
.catch(this.warn);
}

if (res.loadType === "NO_MATCHES") {
if (!player.queue.current) player.destroy();
return interaction.reply({
embeds: [client.ErrorEmbed("No results were found")],
});
return interaction
.editReply({
embeds: [client.ErrorEmbed("No results were found")],
})
.catch(this.warn);
}

if (res.loadType === "TRACK_LOADED" || res.loadType === "SEARCH_RESULT") {
Expand All @@ -48,23 +60,21 @@ const command = new SlashCommand()
let embed = client
.Embed()
.setAuthor("Added to queue", client.config.iconURL)
// display the track thumnaill
.setThumbnail(res.tracks[0].thumbnail)
.setDescription(`[${res.tracks[0].title}](${res.tracks[0].uri})`)
.addField("Author", res.tracks[0].author, true)
// snow duration of the current song
.addField(
"Duration",
res.tracks[0].isStream
? "LIVE"
: `${client.ms(res.tracks[0].duration, {
colonNotation: true,
})}`,
colonNotation: true,
})}`,
true
)
);
if (player.queue.totalSize > 1)
embed.addField("Position in queue", `${player.queue.size - 0}`, true);
return interaction.reply({ embeds: [embed] });
return interaction.editReply({ embeds: [embed] }).catch(this.warn);
}

if (res.loadType === "PLAYLIST_LOADED") {
Expand All @@ -78,7 +88,6 @@ const command = new SlashCommand()
let embed = client
.Embed()
.setAuthor("Playlist added to queue", client.config.iconURL)
// display thumnail of the first track
.setThumbnail(res.tracks[0].thumbnail)
.setDescription(`[${res.playlist.name}](${query})`)
.addField("Enqueued", `\`${res.tracks.length}\` songs`, false)
Expand All @@ -89,7 +98,7 @@ const command = new SlashCommand()
})}\``,
false
);
return interaction.reply({ embeds: [embed] });
return interaction.editReply({ embeds: [embed] }).catch(this.warn);
}
});

Expand Down
6 changes: 1 addition & 5 deletions commands/slash/skip.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ const command = new SlashCommand()
let player = client.manager.players.get(interaction.guild.id);
if (!player)
return interaction.reply({
embeds: [
client.ErrorEmbed(
"There's nothing to skipped!"
),
],
embeds: [client.ErrorEmbed("There's nothing to skipped!")],
});

player.stop();
Expand Down
8 changes: 5 additions & 3 deletions deploy/destory.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ const rl = readline.createInterface({
);
for (let i = 0; i < commands.length; i++) {
const cmd = commands[i];
await rest.delete(
Routes.applicationGuildCommand(config.clientId, guild, cmd.id)
);
await rest
.delete(
Routes.applicationGuildCommand(config.clientId, guild, cmd.id)
)
.catch(console.log);
console.log("Deleted command: " + cmd.name);
}
if (commands.length === 0)
Expand Down
8 changes: 5 additions & 3 deletions deploy/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ const LoadCommands = require("../util/loadCommands");
});

console.log("Deploying commands to global...");
await rest.put(Routes.applicationCommands(config.clientId), {
body: commands,
});
await rest
.put(Routes.applicationCommands(config.clientId), {
body: commands,
})
.catch(console.log);
console.log("Successfully deployed commands!");
})();
8 changes: 5 additions & 3 deletions deploy/guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ const rl = readline.createInterface({
"Enter the guild id you wanted to deploy commands: ",
async (guild) => {
console.log("Deploying commands to guild...");
await rest.put(Routes.applicationGuildCommands(config.clientId, guild), {
body: commands,
});
await rest
.put(Routes.applicationGuildCommands(config.clientId, guild), {
body: commands,
})
.catch(console.log);
console.log("Successfully deployed commands!");
rl.close();
}
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const DiscordMusicBot = require("./lib/DiscordMusicBot");
const client = new DiscordMusicBot();

// Make sure your config.js is filled out
console.log("Make sure to fill in the config.js before starting the bot.");

module.exports = client;
23 changes: 15 additions & 8 deletions lib/DiscordMusicBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ class DiscordMusicBot extends Client {
}`
)
)
// on LOAD_FAILED send error message
.on("loadFailed", (node, type, error) =>
this.warn(
`Node: ${node.options.identifier} | Failed to load ${type}: ${error.message}`
)
)
// on TRACK_START send message
.on("trackStart", async (player, track) => {
this.warn(
`Player: ${
Expand All @@ -168,23 +175,23 @@ class DiscordMusicBot extends Client {
// show the duration of the track but if it's live say that it's "LIVE" if it's not anumber say it's live
.addField(
"Duration",
track.isStream
track.isStream
? "LIVE"
: `${prettyMilliseconds(track.duration, {
colonNotation: true,
})}`,
colonNotation: true,
})}`,
true
)
console.log(TrackStartedEmbed);
// .setTimestamp()
// .setFooter("Started playing at");
);
// .setTimestamp()
// .setFooter("Started playing at");

let NowPlaying = await client.channels.cache
.get(player.textChannel)
.send({
embeds: [TrackStartedEmbed],
components: [client.createController(player.options.guild)],
});
})
.catch(this.warn);
player.setNowplayingMessage(NowPlaying);
})
.on("queueEnd", (player) => {
Expand Down
5 changes: 5 additions & 0 deletions lib/EpicPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ Structure.extend(
"Player",
(Player) =>
class extends Player {
constructor(...props) {
super(...props);
this.twentyFourSeven = false;
}

/**
* Sets now playing message for deleting next time
* @param {Message} message
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"discord-music"
],
"author": "SudhanPlayz",
"license": "SEE LICENSE IN LICENSE",
"license": "LICENSE.md",
"bugs": {
"url": "https://github.com/SudhanPlayz/Discord-MusicBot/issues"
},
Expand Down
39 changes: 20 additions & 19 deletions util/Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,40 @@ module.exports = async (client, interaction) => {
let property = interaction.customId.split(":")[2];
let player = client.manager.get(guild.id);

if (!player){
interaction.reply({
if (!player) {
interaction.reply({
embeds: [client.Embed("There is no player to control in this server.")],
});
setTimeout(() => {
interaction.deleteReply()
interaction.deleteReply();
}, 5000);
return;
}
if (property === "LowVolume") {
player.setVolume(player.volume - 10);
interaction.reply({
interaction.reply({
embeds: [
client.Embed("Successfully set server volume to " + player.volume),
],
});
setTimeout(() => {
interaction.deleteReply()
interaction.deleteReply();
}, 5000);
return;

}

if (property === "Replay") {
if (!player.queue.previous)
interaction.reply({
embeds: [client.ErrorEmbed("There is no previous played song")],
}).then(() => {
setTimeout(() => {
interaction.deleteReply()
}, 5000);
});

interaction
.reply({
embeds: [client.ErrorEmbed("There is no previous played song")],
})
.then(() => {
setTimeout(() => {
interaction.deleteReply();
}, 5000);
});

player.queue.unshift(player.queue.previous);
player.queue.unshift(player.queue.current);
player.stop();
Expand All @@ -50,11 +51,11 @@ module.exports = async (client, interaction) => {
if (property === "PlayAndPause") {
if (player.paused) player.pause(false);
else player.pause(true);
interaction.reply({
interaction.reply({
embeds: [client.Embed(player.paused ? "Paused" : "Resumed")],
})
});
setTimeout(() => {
interaction.deleteReply()
interaction.deleteReply();
}, 5000);
return;
}
Expand All @@ -70,9 +71,9 @@ module.exports = async (client, interaction) => {
embeds: [
client.Embed("Successfully set server volume to " + player.volume),
],
})
});
setTimeout(() => {
interaction.deleteReply()
interaction.deleteReply();
}, 5000);
return;
}
Expand Down

0 comments on commit 0906fbd

Please sign in to comment.