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

Commit

Permalink
Add ContextMenus Limit 5 Context!
Browse files Browse the repository at this point in the history
  • Loading branch information
Adivise committed Mar 10, 2022
1 parent 872dc77 commit 379ae22
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 0 deletions.
28 changes: 28 additions & 0 deletions slashcommands/Context/Leave.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const { ContextMenuInteraction, MessageEmbed } = require('discord.js');

module.exports = {
name: "Context | Stop",
type: 3,
/**
* @param {ContextMenuInteraction} interaction
*/
run: async (interaction, client, user, language) => {
await interaction.deferReply({ ephemeral: false });
const msg = await interaction.editReply(`${client.i18n.get(language, "music", "leave_loading")}`);

const player = client.manager.get(interaction.guild.id);
if (!player) return msg.edit(`${client.i18n.get(language, "noplayer", "no_player")}`);
const { channel } = interaction.member.voice;
if (!channel || interaction.member.voice.channel !== interaction.guild.me.voice.channel) return msg.edit(`${client.i18n.get(language, "noplayer", "no_voice")}`);

await player.destroy();

const embed = new MessageEmbed()
.setDescription(`${client.i18n.get(language, "music", "leave_msg", {
channel: channel.name
})}`)
.setColor(client.color);

msg.edit({ content: " ", embeds: [embed] })
}
}
37 changes: 37 additions & 0 deletions slashcommands/Context/Loop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const { ContextMenuInteraction, MessageEmbed } = require('discord.js');

module.exports = {
name: "Context | Loop",
type: 3,
/**
* @param {ContextMenuInteraction} interaction
*/
run: async (interaction, client, user, language) => {
await interaction.deferReply({ ephemeral: false });
const msg = await interaction.editReply(`${client.i18n.get(language, "music", "loopall_loading")}`);

const player = client.manager.get(interaction.guild.id);
if (!player) return msg.edit(`${client.i18n.get(language, "noplayer", "no_player")}`);
const { channel } = interaction.member.voice;
if (!channel || interaction.member.voice.channel !== interaction.guild.me.voice.channel) return msg.edit(`${client.i18n.get(language, "noplayer", "no_voice")}`);

if (player.queueRepeat === true) {
player.setQueueRepeat(false)

const unloopall = new MessageEmbed()
.setDescription(`${client.i18n.get(language, "music", "unloopall")}`)
.setColor(client.color);

return msg.edit({ content: ' ', embeds: [unloopall] });
}
else {
player.setQueueRepeat(true);

const loopall = new MessageEmbed()
.setDescription(`${client.i18n.get(language, "music", "loopall")}`)
.setColor(client.color);

return msg.edit({ content: ' ', embeds: [loopall] });
}
}
};
84 changes: 84 additions & 0 deletions slashcommands/Context/Play.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
const { ContextMenuInteraction, MessageEmbed, Permissions } = require('discord.js');
const { convertTime } = require("../../structures/convert.js");

module.exports = {
name: "Context | Play",
type: 3,
/**
* @param {ContextMenuInteraction} interaction
*/
run: async (interaction, client, user, language) => {
await interaction.deferReply({ ephemeral: false });

const value = (interaction.channel.messages.cache.get(interaction.targetId).content ?? await interaction.channel.messages.fetch(interaction.targetId));
if (!value.startsWith('https')) return interaction.editReply(`${client.i18n.get(language, "music", "play_startwith")}`);

const msg = await interaction.editReply(`${client.i18n.get(language, "music", "play_loading")}`);

const { channel } = interaction.member.voice;
if (!channel) return msg.edit(`${client.i18n.get(language, "music", "play_invoice")}`);
if (!channel.permissionsFor(interaction.guild.me).has(Permissions.FLAGS.CONNECT)) return msg.edit(`${client.i18n.get(language, "music", "play_join")}`);
if (!channel.permissionsFor(interaction.guild.me).has(Permissions.FLAGS.SPEAK)) return msg.edit(`${client.i18n.get(language, "music", "play_speak")}`);

const player = await client.manager.create({
guild: interaction.guild.id,
voiceChannel: interaction.member.voice.channel.id,
textChannel: interaction.channel.id,
selfDeafen: true,
});

const state = player.state;
if (state != "CONNECTED") await player.connect();
const res = await client.manager.search(value, interaction.user);
if(res.loadType != "NO_MATCHES") {
if(res.loadType == "TRACK_LOADED") {
player.queue.add(res.tracks[0]);
const embed = new MessageEmbed()
.setDescription(`${client.i18n.get(language, "music", "play_track", {
title: res.tracks[0].title,
url: res.tracks[0].uri,
duration: convertTime(res.tracks[0].duration, true),
request: res.tracks[0].requester
})}`)
.setColor(client.color)
msg.edit({ content: " ", embeds: [embed] });
if(!player.playing) player.play();
}
else if(res.loadType == "PLAYLIST_LOADED") {
player.queue.add(res.tracks)
const embed = new MessageEmbed()
.setDescription(`${client.i18n.get(language, "music", "play_playlist", {
title: res.playlist.name,
url: value,
duration: convertTime(res.playlist.duration),
songs: res.tracks.length,
request: res.tracks[0].requester
})}`)
.setColor(client.color)
msg.edit({ content: " ", embeds: [embed] });
if(!player.playing) player.play();
}
else if(res.loadType == "SEARCH_RESULT") {
player.queue.add(res.tracks[0]);
const embed = new MessageEmbed()
.setDescription(`${client.i18n.get(language, "music", "play_result", {
title: res.tracks[0].title,
url: res.tracks[0].uri,
duration: convertTime(res.tracks[0].duration, true),
request: res.tracks[0].requester
})}`)
.setColor(client.color)
msg.edit({ content: " ", embeds: [embed] });
if(!player.playing) player.play();
}
else if(res.loadType == "LOAD_FAILED") {
msg.edit(`${client.i18n.get(language, "music", "play_fail")}`);
player.destroy();
}
}
else {
msg.edit(`${client.i18n.get(language, "music", "play_match")}`);
player.destroy();
}
}
}
26 changes: 26 additions & 0 deletions slashcommands/Context/Shuffle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const { ContextMenuInteraction, MessageEmbed } = require('discord.js');

module.exports = {
name: "Context | Shuffle",
type: 3,
/**
* @param {ContextMenuInteraction} interaction
*/
run: async (interaction, client, user, language) => {
await interaction.deferReply({ ephemeral: false });
const msg = await interaction.editReply(`${client.i18n.get(language, "music", "shuffle_loading")}`);

const player = client.manager.get(interaction.guild.id);
if (!player) return msg.edit(`${client.i18n.get(language, "noplayer", "no_player")}`);
const { channel } = interaction.member.voice;
if (!channel || interaction.member.voice.channel !== interaction.guild.me.voice.channel) return msg.edit(`${client.i18n.get(language, "noplayer", "no_voice")}`);

await player.queue.shuffle();

const shuffle = new MessageEmbed()
.setDescription(`${client.i18n.get(language, "music", "shuffle_msg")}`)
.setColor(client.color);

msg.edit({ content: " ", embeds: [shuffle] });
}
}
26 changes: 26 additions & 0 deletions slashcommands/Context/Skip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const { ContextMenuInteraction, MessageEmbed } = require('discord.js');

module.exports = {
name: "Context | Skip",
type: 3,
/**
* @param {ContextMenuInteraction} interaction
*/
run: async (interaction, client, user, language) => {
await interaction.deferReply({ ephemeral: false });
const msg = await interaction.editReply(`${client.i18n.get(language, "music", "skip_loading")}`);

const player = client.manager.get(interaction.guild.id);
if (!player) return msg.edit(`${client.i18n.get(language, "noplayer", "no_player")}`);
const { channel } = interaction.member.voice;
if (!channel || interaction.member.voice.channel !== interaction.guild.me.voice.channel) return msg.edit(`${client.i18n.get(language, "noplayer", "no_voice")}`);

await player.stop();

const skipped = new MessageEmbed()
.setDescription(`${client.i18n.get(language, "music", "skip_msg")}`)
.setColor(client.color);

msg.edit({ content: " ", embeds: [skipped] });
}
}

0 comments on commit 379ae22

Please sign in to comment.