Bot wont talk & no error, how do i debug?

(selected opus tag bc i had to, to post idk what it is) how do i debug this? since it says nothing in logs and doesnt even light up green code (voiceConnectionAudioPlayer.player.play(...) is actually ran):
function sayAsUser(text, userId)
{
const voice = voicesJSON();
const name = getRandomInt(1000).toString() + ".wav";
const filePath = `D:/js projects/schizophrenia discord bot/sounds/${name}`;
// say.speak(text, voice.userVoices.voice[voice.userVoices.userId.indexOf(userId)]);
say.export(text, voice.userVoices.voice[voice.userVoices.userId.indexOf(userId)], 1, filePath, (e) => {
console.log(e);
});

console.log("trying to play audio...");
const watcher = fs.watch("D:/js projects/schizophrenia discord bot/sounds", (eventType, file) => {
if(eventType == "rename" && file == name)
{
console.log("actually playing audio...");
voiceConnectionAudioPlayer.player.play(createAudioResource(fs.createReadStream(filePath)));
watcher.close();
}
console.log(file);
});

}
function sayAsUser(text, userId)
{
const voice = voicesJSON();
const name = getRandomInt(1000).toString() + ".wav";
const filePath = `D:/js projects/schizophrenia discord bot/sounds/${name}`;
// say.speak(text, voice.userVoices.voice[voice.userVoices.userId.indexOf(userId)]);
say.export(text, voice.userVoices.voice[voice.userVoices.userId.indexOf(userId)], 1, filePath, (e) => {
console.log(e);
});

console.log("trying to play audio...");
const watcher = fs.watch("D:/js projects/schizophrenia discord bot/sounds", (eventType, file) => {
if(eventType == "rename" && file == name)
{
console.log("actually playing audio...");
voiceConnectionAudioPlayer.player.play(createAudioResource(fs.createReadStream(filePath)));
watcher.close();
}
console.log(file);
});

}
19 Replies
d.js toolkit
d.js toolkit•9mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - āœ… Marked as resolved by OP
skg
skgOP•9mo ago
[email protected] @discordjs/[email protected] and node: v21.5.0
and this is how i get the voice connection:
client.on("interactionCreate", (interaction) => // on command
{
if(!interaction.isChatInputCommand()) return;

if(interaction.commandName == "join")
{
try
{
const voiceChannelId = interaction.member.voice.channel.id;


voiceConnection = joinVoiceChannel({
channelId: voiceChannelId,
guildId: interaction.guildId,
adapterCreator: interaction.guild.voiceAdapterCreator
});
interaction.reply("Joined voice chat succesfully!");
console.log(`Joining vc ${interaction.member.voice.channel.name} (ID: ${voiceChannelId})`);

voiceConnectionAudioPlayer = voiceConnection.subscribe(createAudioPlayer());

} catch (error) {
console.log(error);
}
}
});
and this is how i get the voice connection:
client.on("interactionCreate", (interaction) => // on command
{
if(!interaction.isChatInputCommand()) return;

if(interaction.commandName == "join")
{
try
{
const voiceChannelId = interaction.member.voice.channel.id;


voiceConnection = joinVoiceChannel({
channelId: voiceChannelId,
guildId: interaction.guildId,
adapterCreator: interaction.guild.voiceAdapterCreator
});
interaction.reply("Joined voice chat succesfully!");
console.log(`Joining vc ${interaction.member.voice.channel.name} (ID: ${voiceChannelId})`);

voiceConnectionAudioPlayer = voiceConnection.subscribe(createAudioPlayer());

} catch (error) {
console.log(error);
}
}
});
here are my intents:
const client = new Client({
intents: [IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.MessageContent,
IntentsBitField.Flags.GuildVoiceStates]
});
const client = new Client({
intents: [IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.MessageContent,
IntentsBitField.Flags.GuildVoiceStates]
});
ping me if you have a response .wav file btw
pat
pat•9mo ago
first check it's actually reading the file correctly & the types here may have a hint
d.js docs
d.js docs•9mo ago
:function: createAudioResource @0.17.0 Creates an audio resource that can be played by audio players.
pat
pat•9mo ago
No description
pat
pat•9mo ago
notably, that readstream isn't explicitly mentioned
skg
skgOP•9mo ago
how do i check that
pat
pat•9mo ago
start by breaking down this line into separate calls voiceConnectionAudioPlayer.player.play(createAudioResource(fs.createReadStream(filePath))); but i suspect this is the issue iirc you can just pass the path into createAudioResource
skg
skgOP•9mo ago
im pretty sure i tried that already, but i changed it cuz it was in some example ill try it again tho
pat
pat•9mo ago
ah u are right you can add a listener to the error event on audioplayer
skg
skgOP•9mo ago
wtf this works i swear i tried this before 😭 i hate coding ong well ty so much ā¤ļø
pat
pat•9mo ago
yw
skg
skgOP•9mo ago
btw do you know if i can delete the mp4 file right after i give the command to play it?
pat
pat•9mo ago
i think so should be read entirely into memory
skg
skgOP•9mo ago
oh gotcha how do you delete files in nodejs btw lol
pat
pat•9mo ago
idk google it
skg
skgOP•9mo ago
oh its fs.rm why is it an abreviation
pat
pat•9mo ago
cause rm is a native command in every system
skg
skgOP•9mo ago
ig

Did you find this page helpful?