-
-
Notifications
You must be signed in to change notification settings - Fork 406
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Util function for checking voice channel + format code
Signed-off-by: TannerGabriel <gabrieltanner.code@gmail.com>
- Loading branch information
1 parent
8fd0ad9
commit 6eb556b
Showing
20 changed files
with
573 additions
and
699 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,13 +1,13 @@ | ||
const {Client, Collection, GatewayIntentBits, Partials} = require('discord.js'); | ||
|
||
module.exports = class extends Client { | ||
constructor(config) { | ||
super({ | ||
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates] | ||
}); | ||
constructor(config) { | ||
super({ | ||
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates] | ||
}); | ||
|
||
this.commands = new Collection(); | ||
this.commands = new Collection(); | ||
|
||
this.config = config; | ||
} | ||
this.config = config; | ||
} | ||
}; |
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,42 +1,42 @@ | ||
const {ApplicationCommandOptionType } = require('discord.js'); | ||
const {ApplicationCommandOptionType} = require('discord.js'); | ||
|
||
module.exports = { | ||
name: 'ban', | ||
description: 'Ban a player', | ||
options: [ | ||
{ | ||
name: 'user', | ||
type: ApplicationCommandOptionType.User, | ||
description: 'The user you want to ban', | ||
required: true, | ||
}, | ||
], | ||
execute(interaction, client) { | ||
const member = interaction.options.getUser('user'); | ||
name: 'ban', | ||
description: 'Ban a player', | ||
options: [ | ||
{ | ||
name: 'user', | ||
type: ApplicationCommandOptionType.User, | ||
description: 'The user you want to ban', | ||
required: true, | ||
}, | ||
], | ||
execute(interaction, client) { | ||
const member = interaction.options.getUser('user'); | ||
|
||
if (!member) { | ||
return interaction.reply('You need to mention the member you want to ban him'); | ||
} | ||
if (!member) { | ||
return interaction.reply('You need to mention the member you want to ban him'); | ||
} | ||
|
||
if (!interaction.member.permissions.has('BAN_MEMBERS')) { | ||
return interaction.reply("I can't ban this user."); | ||
} | ||
if (!interaction.member.permissions.has('BAN_MEMBERS')) { | ||
return interaction.reply("I can't ban this user."); | ||
} | ||
|
||
const userinfo = client.users.cache.getMember(member); | ||
const userinfo = client.users.cache.getMember(member); | ||
|
||
return interaction.guild.members | ||
.ban(member) | ||
.then(() => { | ||
interaction.reply({ | ||
content: `${userinfo.username} was banned.`, | ||
ephemeral: true, | ||
}); | ||
}) | ||
.catch(error => | ||
interaction.reply({ | ||
content: `Sorry, an error occured.`, | ||
ephemeral: true, | ||
}), | ||
); | ||
}, | ||
return interaction.guild.members | ||
.ban(member) | ||
.then(() => { | ||
interaction.reply({ | ||
content: `${userinfo.username} was banned.`, | ||
ephemeral: true, | ||
}); | ||
}) | ||
.catch(error => | ||
interaction.reply({ | ||
content: `Sorry, an error occured.`, | ||
ephemeral: true, | ||
}), | ||
); | ||
}, | ||
}; |
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,20 +1,20 @@ | ||
const fs = require('fs'); | ||
|
||
module.exports = { | ||
name: 'help', | ||
description: 'List all available commands.', | ||
execute(interaction) { | ||
let str = ''; | ||
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js')); | ||
name: 'help', | ||
description: 'List all available commands.', | ||
execute(interaction) { | ||
let str = ''; | ||
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js')); | ||
|
||
for (const file of commandFiles) { | ||
const command = require(`./${file}`); | ||
str += `Name: ${command.name}, Description: ${command.description} \n`; | ||
} | ||
for (const file of commandFiles) { | ||
const command = require(`./${file}`); | ||
str += `Name: ${command.name}, Description: ${command.description} \n`; | ||
} | ||
|
||
return void interaction.reply({ | ||
content: str, | ||
ephemeral: true, | ||
}); | ||
}, | ||
return void interaction.reply({ | ||
content: str, | ||
ephemeral: true, | ||
}); | ||
}, | ||
}; |
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,73 +1,62 @@ | ||
const {GuildMember, ApplicationCommandOptionType} = require('discord.js'); | ||
const {QueueRepeatMode, useQueue} = require('discord-player'); | ||
const {isInVoiceChannel} = require("../utils/voicechannel"); | ||
|
||
module.exports = { | ||
name: 'loop', | ||
description: 'Sets loop mode', | ||
options: [ | ||
{ | ||
name: 'mode', | ||
type: ApplicationCommandOptionType.Integer, | ||
description: 'Loop type', | ||
required: true, | ||
choices: [ | ||
name: 'loop', | ||
description: 'Sets loop mode', | ||
options: [ | ||
{ | ||
name: 'Off', | ||
value: QueueRepeatMode.OFF, | ||
name: 'mode', | ||
type: ApplicationCommandOptionType.Integer, | ||
description: 'Loop type', | ||
required: true, | ||
choices: [ | ||
{ | ||
name: 'Off', | ||
value: QueueRepeatMode.OFF, | ||
}, | ||
{ | ||
name: 'Track', | ||
value: QueueRepeatMode.TRACK, | ||
}, | ||
{ | ||
name: 'Queue', | ||
value: QueueRepeatMode.QUEUE, | ||
}, | ||
{ | ||
name: 'Autoplay', | ||
value: QueueRepeatMode.AUTOPLAY, | ||
}, | ||
], | ||
}, | ||
{ | ||
name: 'Track', | ||
value: QueueRepeatMode.TRACK, | ||
}, | ||
{ | ||
name: 'Queue', | ||
value: QueueRepeatMode.QUEUE, | ||
}, | ||
{ | ||
name: 'Autoplay', | ||
value: QueueRepeatMode.AUTOPLAY, | ||
}, | ||
], | ||
}, | ||
], | ||
async execute(interaction) { | ||
try { | ||
if (!(interaction.member instanceof GuildMember) || !interaction.member.voice.channel) { | ||
return void interaction.reply({ | ||
content: 'You are not in a voice channel!', | ||
ephemeral: true, | ||
}); | ||
} | ||
], | ||
async execute(interaction) { | ||
try { | ||
const inVoiceChannel = isInVoiceChannel(interaction) | ||
if (!inVoiceChannel) { | ||
return | ||
} | ||
|
||
if ( | ||
interaction.guild.members.me.voice.channelId && | ||
interaction.member.voice.channelId !== interaction.guild.members.me.voice.channelId | ||
) { | ||
return void interaction.reply({ | ||
content: 'You are not in my voice channel!', | ||
ephemeral: true, | ||
}); | ||
} | ||
await interaction.deferReply(); | ||
|
||
await interaction.deferReply(); | ||
const queue = useQueue(interaction.guild.id) | ||
if (!queue || !queue.currentTrack) { | ||
return void interaction.followUp({content: '❌ | No music is being played!'}); | ||
} | ||
|
||
const queue = useQueue(interaction.guild.id) | ||
if (!queue || !queue.currentTrack) { | ||
return void interaction.followUp({content: '❌ | No music is being played!'}); | ||
} | ||
const loopMode = interaction.options.getInteger('mode'); | ||
queue.setRepeatMode(loopMode); | ||
const mode = loopMode === QueueRepeatMode.TRACK ? '🔂' : loopMode === QueueRepeatMode.QUEUE ? '🔁' : '▶'; | ||
|
||
const loopMode = interaction.options.getInteger('mode'); | ||
queue.setRepeatMode(loopMode); | ||
const mode = loopMode === QueueRepeatMode.TRACK ? '🔂' : loopMode === QueueRepeatMode.QUEUE ? '🔁' : '▶'; | ||
|
||
return void interaction.followUp({ | ||
content: `${mode} | Updated loop mode!`, | ||
}); | ||
} catch (error) { | ||
console.log(error); | ||
interaction.followUp({ | ||
content: 'There was an error trying to execute that command: ' + error.message, | ||
}); | ||
} | ||
}, | ||
return void interaction.followUp({ | ||
content: `${mode} | Updated loop mode!`, | ||
}); | ||
} catch (error) { | ||
console.log(error); | ||
interaction.followUp({ | ||
content: 'There was an error trying to execute that command: ' + error.message, | ||
}); | ||
} | ||
}, | ||
}; |
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,63 +1,52 @@ | ||
const {GuildMember, ApplicationCommandOptionType } = require('discord.js'); | ||
const {GuildMember, ApplicationCommandOptionType} = require('discord.js'); | ||
const {useQueue} = require("discord-player"); | ||
const {isInVoiceChannel} = require("../utils/voicechannel"); | ||
|
||
module.exports = { | ||
name: 'move', | ||
description: 'move song position in the queue!', | ||
options: [ | ||
{ | ||
name: 'track', | ||
type: ApplicationCommandOptionType.Integer, | ||
description: 'The track number you want to move', | ||
required: true, | ||
}, | ||
{ | ||
name: 'position', | ||
type: ApplicationCommandOptionType.Integer, | ||
description: 'The position to move it to', | ||
required: true, | ||
}, | ||
], | ||
async execute(interaction) { | ||
if (!(interaction.member instanceof GuildMember) || !interaction.member.voice.channel) { | ||
return void interaction.reply({ | ||
content: 'You are not in a voice channel!', | ||
ephemeral: true, | ||
}); | ||
} | ||
name: 'move', | ||
description: 'move song position in the queue!', | ||
options: [ | ||
{ | ||
name: 'track', | ||
type: ApplicationCommandOptionType.Integer, | ||
description: 'The track number you want to move', | ||
required: true, | ||
}, | ||
{ | ||
name: 'position', | ||
type: ApplicationCommandOptionType.Integer, | ||
description: 'The position to move it to', | ||
required: true, | ||
}, | ||
], | ||
async execute(interaction) { | ||
const inVoiceChannel = isInVoiceChannel(interaction) | ||
if (!inVoiceChannel) { | ||
return | ||
} | ||
|
||
if ( | ||
interaction.guild.members.me.voice.channelId && | ||
interaction.member.voice.channelId !== interaction.guild.members.me.voice.channelId | ||
) { | ||
return void interaction.reply({ | ||
content: 'You are not in my voice channel!', | ||
ephemeral: true, | ||
}); | ||
} | ||
await interaction.deferReply(); | ||
const queue = useQueue(interaction.guild.id) | ||
|
||
await interaction.deferReply(); | ||
const queue = useQueue(interaction.guild.id) | ||
if (!queue || !queue.currentTrack) | ||
return void interaction.followUp({content: '❌ | No music is being played!'}); | ||
|
||
if (!queue || !queue.currentTrack) | ||
return void interaction.followUp({content: '❌ | No music is being played!'}); | ||
const queueNumbers = [interaction.options.getInteger('track') - 1, interaction.options.getInteger('position') - 1]; | ||
|
||
const queueNumbers = [interaction.options.getInteger('track') - 1, interaction.options.getInteger('position') - 1]; | ||
if (queueNumbers[0] > queue.tracks.size || queueNumbers[1] > queue.tracks.size) | ||
return void interaction.followUp({content: '❌ | Track number greater than queue depth!'}); | ||
|
||
if (queueNumbers[0] > queue.tracks.size || queueNumbers[1] > queue.tracks.size) | ||
return void interaction.followUp({content: '❌ | Track number greater than queue depth!'}); | ||
|
||
try { | ||
const track = queue.node.remove(queueNumbers[0]); | ||
queue.node.insert(track, queueNumbers[1]); | ||
return void interaction.followUp({ | ||
content: `✅ | Moved **${track}**!`, | ||
}); | ||
} catch (error) { | ||
console.log(error); | ||
return void interaction.followUp({ | ||
content: '❌ | Something went wrong!', | ||
}); | ||
} | ||
}, | ||
try { | ||
const track = queue.node.remove(queueNumbers[0]); | ||
queue.node.insert(track, queueNumbers[1]); | ||
return void interaction.followUp({ | ||
content: `✅ | Moved **${track}**!`, | ||
}); | ||
} catch (error) { | ||
console.log(error); | ||
return void interaction.followUp({ | ||
content: '❌ | Something went wrong!', | ||
}); | ||
} | ||
}, | ||
}; |
Oops, something went wrong.