Add an overlay soundboard and fix playback command bugs.

Stop was advancing the queue, history overwrote the day file, and slash commands often never replied; soundboard clips now mix on top of the current track.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Patryk Koreń
2026-09-13 17:03:02 +02:00
parent 2eb8d25a2d
commit ad87d3fbb8
19 changed files with 708 additions and 126 deletions

View File

@@ -3,8 +3,9 @@ import dotenv from 'dotenv';
dotenv.config()
import { Client, Events, GatewayIntentBits, MessageFlags, REST, Routes } from 'discord.js';
import { commands } from "./commands";
import { AudioPlayerState, createAudioPlayer } from '@discordjs/voice';
import { connectToChannel, playSong } from './util/helpers';
import { handleSoundboardAutocomplete } from "./commands/soundboard";
import { handleSoundboardButton } from "./soundboard";
import { AudioPlayerStatus, AudioPlayerState, createAudioPlayer } from '@discordjs/voice';
import { updatePlayer } from './playback';
import SpotifyWebApi from 'spotify-web-api-node';
@@ -13,8 +14,10 @@ export const HISTORY_DIR_PATH = process.env.HISTORY_DIR_PATH ?? "./history";
// AUDIO
export const player = createAudioPlayer();
player.on('stateChange', (oldState: AudioPlayerState, newState: AudioPlayerState) => {
updatePlayer()
player.on('stateChange', (_oldState: AudioPlayerState, newState: AudioPlayerState) => {
if (newState.status === AudioPlayerStatus.Idle) {
updatePlayer()
}
});
@@ -62,6 +65,26 @@ async function registerCommands() {
client.login(process.env.DISCORD_TOKEN!);
client.on(Events.InteractionCreate, async (interaction) => {
if (interaction.isButton() && (interaction.customId.startsWith("sbplay:") || interaction.customId.startsWith("sbpage:"))) {
try {
await handleSoundboardButton(interaction);
} catch (error) {
console.error(error);
}
return;
}
if (interaction.isAutocomplete()) {
if (interaction.commandName === "soundboard") {
try {
await handleSoundboardAutocomplete(interaction);
} catch (error) {
console.error(error);
}
}
return;
}
if (!interaction.isChatInputCommand()) return;
const cmd = commands[interaction.commandName];
if (!cmd) {