Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: disabled volume buttons when volume goes to 100 or 0 #1629

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions config.json.example

This file was deleted.

72 changes: 70 additions & 2 deletions structs/MusicQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,23 @@ import {
VoiceConnectionStatus
} from "@discordjs/voice";
import {
ActionRow,
ActionRowBuilder,
ActionRowComponent,
AnyComponent,
AnyComponentBuilder,
APIButtonComponent,
ButtonBuilder,
ButtonComponent,
ButtonInteraction,
ButtonStyle,
CommandInteraction,
ComponentType,
GuildMember,
Interaction,
Message,
MessageActionRowComponent,
MessageActionRowComponentBuilder,
TextChannel
} from "discord.js";
import { promisify } from "node:util";
Expand Down Expand Up @@ -243,6 +252,32 @@ export class MusicQueue {
safeReply(interaction, i18n.__mf("play.decreasedVolume", { author: interaction.user, volume: this.volume })).catch(
console.error
);

if (this.volume == 0 || this.volume == 90) {
const newActionRowEmbeds = interaction.message.components.map((oldActionRow) => {
const updatedActionRow = new ActionRowBuilder<MessageActionRowComponentBuilder>();

updatedActionRow.addComponents(
oldActionRow.components.map((buttonComponent) => {
if (buttonComponent.type == ComponentType.Button) {
const newButton = ButtonBuilder.from(buttonComponent);

if (this.volume == 90) {
newButton.setDisabled(false);
} else if (this.volume == 0) {
const isDisabled = buttonComponent.customId == "decrease_volume" ? true : false;
newButton.setDisabled(isDisabled);
}
return newButton;
} else {
return buttonComponent as unknown as MessageActionRowComponentBuilder;
}
})
);
return updatedActionRow;
});
interaction.message.edit({ components: newActionRowEmbeds });
}
}

private async handleIncreaseVolume(interaction: ButtonInteraction): Promise<void> {
Expand All @@ -257,6 +292,31 @@ export class MusicQueue {
safeReply(interaction, i18n.__mf("play.increasedVolume", { author: interaction.user, volume: this.volume })).catch(
console.error
);
if (this.volume == 100 || this.volume == 10) {
const newActionRowEmbeds = interaction.message.components.map((oldActionRow) => {
const updatedActionRow = new ActionRowBuilder<MessageActionRowComponentBuilder>();
updatedActionRow.addComponents(
oldActionRow.components.map((buttonComponent) => {
if (buttonComponent.type == ComponentType.Button) {
const newButton = ButtonBuilder.from(buttonComponent);
let isDisabled: boolean;
if (this.volume === 100) {
isDisabled = buttonComponent.customId === "increase_volume";
newButton.setDisabled(isDisabled);
}
if (this.volume === 10) {
newButton.setDisabled(false);
}
return newButton;
} else {
return buttonComponent as unknown as MessageActionRowComponentBuilder;
}
})
);
return updatedActionRow;
});
interaction.message.edit({ components: newActionRowEmbeds });
}
}

private async handleLoop(interaction: ButtonInteraction): Promise<void> {
Expand Down Expand Up @@ -287,8 +347,16 @@ export class MusicQueue {
new ButtonBuilder().setCustomId("skip").setLabel("⏭").setStyle(ButtonStyle.Secondary),
new ButtonBuilder().setCustomId("play_pause").setLabel("⏯").setStyle(ButtonStyle.Secondary),
new ButtonBuilder().setCustomId("mute").setLabel("🔇").setStyle(ButtonStyle.Secondary),
new ButtonBuilder().setCustomId("decrease_volume").setLabel("🔉").setStyle(ButtonStyle.Secondary),
new ButtonBuilder().setCustomId("increase_volume").setLabel("🔊").setStyle(ButtonStyle.Secondary)
new ButtonBuilder()
.setCustomId("decrease_volume")
.setLabel("🔉")
.setStyle(ButtonStyle.Secondary)
.setDisabled(config.DEFAULT_VOLUME == 0),
new ButtonBuilder()
.setCustomId("increase_volume")
.setLabel("🔊")
.setStyle(ButtonStyle.Secondary)
.setDisabled(config.DEFAULT_VOLUME == 100)
);
const secondRow = new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder().setCustomId("loop").setLabel("🔁").setStyle(ButtonStyle.Secondary),
Expand Down