-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[New] Added volume command to change the bots volume
- Loading branch information
Showing
1 changed file
with
173 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,173 @@ | ||
const { SlashCommandBuilder } = require("@discordjs/builders"); | ||
const { embedMessage } = require("../../modules/embedSimple"); | ||
|
||
module.exports = { | ||
name: "volume", | ||
args: true, | ||
aliases: ["vol"], | ||
description: "Change the bots volume", | ||
usage: "vol || volume <number>", | ||
async run(message, args, client) { | ||
const queue = client.player.getQueue(message.guild); | ||
|
||
if ( | ||
message.guild.me.voice.channelId && | ||
message.member.voice.channelId !== message.guild.me.voice.channelId | ||
) | ||
return await message.channel.send({ | ||
embeds: [ | ||
embedMessage( | ||
"#9dcc37", | ||
`❌ | You must be in my voice channel to change the bot volume!` | ||
), | ||
], | ||
}); | ||
|
||
if (!queue) { | ||
return await message.channel.send({ | ||
embeds: [ | ||
embedMessage( | ||
"#9dcc37", | ||
`❌ | ${message.member.toString()}, There is no queue created for this server!` | ||
), | ||
], | ||
}); | ||
} | ||
|
||
const checkdj = await client.db.get(`djRole_${message.guildId}`); | ||
const userRoles = await message.member.roles.cache.map((role) => role.id); | ||
|
||
if ( | ||
checkdj && | ||
!userRoles.includes(checkdj) && | ||
message.guild.ownerId !== message.author.id | ||
) { | ||
return await message.channel.send({ | ||
embeds: [ | ||
embedMessage( | ||
"#9dcc37", | ||
`You are not allowed to use this command.\n This command is only available for users with the DJ Role: <@&${checkdj}>` | ||
), | ||
], | ||
}); | ||
} | ||
|
||
const volume = Number(args[0]); | ||
console.log(typeof volume); | ||
|
||
if (!args[0]) | ||
return await message.channel.send({ | ||
embeds: [ | ||
embedMessage( | ||
"#9dcc37", | ||
`❌ Please provide the bot volume you wish to set!` | ||
), | ||
], | ||
}); | ||
|
||
if (!volume) | ||
return await message.channel.send({ | ||
embeds: [embedMessage("#9dcc37", `❌ Volume must be a number!`)], | ||
}); | ||
|
||
try { | ||
queue.setVolume(volume); | ||
return await message.channel.send({ | ||
embeds: [ | ||
embedMessage("#9dcc37", `✅ Bot volume has been set to ${volume}`), | ||
], | ||
}); | ||
} catch (error) { | ||
client.logger(error.message, "error"); | ||
return await message.channel.send({ | ||
embeds: [ | ||
embedMessage( | ||
"#9dcc37", | ||
`There was an error setting the bot volume!\nError: ${error.message}` | ||
), | ||
], | ||
}); | ||
} | ||
}, | ||
data: new SlashCommandBuilder() | ||
.setName("volume") | ||
.setDescription("Change the bots volume") | ||
.addIntegerOption((option) => | ||
option.setDescription("new volume").setName("volume").setRequired(true) | ||
), | ||
|
||
async execute(interaction, client) { | ||
await interaction.deferReply(); | ||
const volume = interaction.options.getInteger("volume"); | ||
const queue = client.player.getQueue(interaction.guild); | ||
|
||
if ( | ||
interaction.guild.me.voice.channelId && | ||
interaction.member.voice.channelId !== | ||
interaction.guild.me.voice.channelId | ||
) | ||
return await interaction.followUp({ | ||
embeds: [ | ||
embedMessage( | ||
"#9dcc37", | ||
`❌ | You must be in my voice channel to change the volume!` | ||
), | ||
], | ||
}); | ||
|
||
if (!queue) { | ||
return await interaction.followUp({ | ||
embeds: [ | ||
embedMessage( | ||
"#9dcc37", | ||
`❌ | ${interaction.member.toString()}, There is no queue created for this server!` | ||
), | ||
], | ||
}); | ||
} | ||
|
||
const checkdj = await client.db.get(`djRole_${interaction.guildId}`); | ||
const userRoles = await interaction.member.roles.cache.map( | ||
(role) => role.id | ||
); | ||
|
||
if ( | ||
checkdj && | ||
!userRoles.includes(checkdj) && | ||
interaction.guild.ownerId !== interaction.member.id | ||
) { | ||
return await interaction.followUp({ | ||
embeds: [ | ||
embedMessage( | ||
"#9dcc37", | ||
`You are not allowed to use this command.\n This command is only available for users with the DJ Role: <@&${checkdj}>` | ||
), | ||
], | ||
}); | ||
} | ||
|
||
if (typeof volume === "string") | ||
return await interaction.followUp({ | ||
embeds: [embedMessage("#9dcc37", `❌ Volume must be a number!`)], | ||
}); | ||
|
||
try { | ||
queue.setVolume(volume); | ||
return await interaction.followUp({ | ||
embeds: [ | ||
embedMessage("#9dcc37", `✅ Bot volume has been set to ${volume}`), | ||
], | ||
}); | ||
} catch (error) { | ||
client.logger(error.message, "error"); | ||
return await interaction.followUp({ | ||
embeds: [ | ||
embedMessage( | ||
"#9dcc37", | ||
`There was an error setting the bot volume!\nError: ${error.message}` | ||
), | ||
], | ||
}); | ||
} | ||
}, | ||
}; |