fix: annotate volume command

This commit is contained in:
Marius Begby committed 2023-08-27 13:54:19 +02:00
1 parent 72e2b2aa13
commit e9ed2eb0b8
1 file changed
+21 -9
+21 -9
View File
@@ -1,6 +1,6 @@
import config from 'config'; import config from 'config';
import { useQueue } from 'discord-player'; import { NodeResolvable, useQueue } from 'discord-player';
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
import loggerModule from '../../services/logger'; import loggerModule from '../../services/logger';
import { CommandParams } from '../../types/commandTypes'; import { CommandParams } from '../../types/commandTypes';
@@ -30,15 +30,19 @@ module.exports = {
module: 'slashCommand', module: 'slashCommand',
name: '/volume', name: '/volume',
executionId: executionId, executionId: executionId,
shardId: interaction.guild.shardId, shardId: interaction.guild?.shardId,
guildId: interaction.guild.id guildId: interaction.guild?.id
}); });
if (await notInVoiceChannel({ interaction, executionId })) { if (await notInVoiceChannel({ interaction, executionId })) {
return; return;
} }
const queue = useQueue(interaction.guild.id); if (!interaction.guild) {
return;
}
const queue: NodeResolvable = useQueue(interaction.guild.id)!;
if (await queueDoesNotExist({ interaction, queue, executionId })) { if (await queueDoesNotExist({ interaction, queue, executionId })) {
return; return;
@@ -84,14 +88,22 @@ module.exports = {
queue.node.setVolume(volume); queue.node.setVolume(volume);
logger.debug(`Set volume to ${volume}%.`); logger.debug(`Set volume to ${volume}%.`);
let authorName: string;
if (interaction.member instanceof GuildMember) {
authorName = interaction.member.nickname || interaction.user.username;
} else {
authorName = interaction.user.username;
}
if (volume === 0) { if (volume === 0) {
logger.debug('Responding with success embed.'); logger.debug('Responding with success embed.');
return await interaction.editReply({ return await interaction.editReply({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
.setAuthor({ .setAuthor({
name: interaction.member.nickname || interaction.user.username, name: authorName,
iconURL: interaction.user.avatarURL() iconURL: interaction.user.avatarURL() || ''
}) })
.setDescription( .setDescription(
`**${embedOptions.icons.volumeMuted} Audio muted**\nPlayback audio has been muted, because volume was set to \`${volume}%\`.` `**${embedOptions.icons.volumeMuted} Audio muted**\nPlayback audio has been muted, because volume was set to \`${volume}%\`.`
@@ -106,8 +118,8 @@ module.exports = {
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
.setAuthor({ .setAuthor({
name: interaction.member.nickname || interaction.user.username, name: authorName,
iconURL: interaction.user.avatarURL() iconURL: interaction.user.avatarURL() || ''
}) })
.setDescription( .setDescription(
`**${embedOptions.icons.volumeChanged} Volume changed**\nPlayback volume has been changed to \`${volume}%\`.` `**${embedOptions.icons.volumeChanged} Volume changed**\nPlayback volume has been changed to \`${volume}%\`.`