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ā€¢4mo 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ā€¢4mo 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ā€¢4mo ago
first check it's actually reading the file correctly & the types here may have a hint
d.js docs
d.js docsā€¢4mo ago
:function: createAudioResource @0.17.0 Creates an audio resource that can be played by audio players.
pat
patā€¢4mo ago
No description
pat
patā€¢4mo ago
notably, that readstream isn't explicitly mentioned
skg
skgOPā€¢4mo ago
how do i check that
pat
patā€¢4mo 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ā€¢4mo 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ā€¢4mo ago
ah u are right you can add a listener to the error event on audioplayer
skg
skgOPā€¢4mo ago
wtf this works i swear i tried this before šŸ˜­ i hate coding ong well ty so much ā¤ļø
pat
patā€¢4mo ago
yw
skg
skgOPā€¢4mo ago
btw do you know if i can delete the mp4 file right after i give the command to play it?
pat
patā€¢4mo ago
i think so should be read entirely into memory
skg
skgOPā€¢4mo ago
oh gotcha how do you delete files in nodejs btw lol
pat
patā€¢4mo ago
idk google it
skg
skgOPā€¢4mo ago
oh its fs.rm why is it an abreviation
pat
patā€¢4mo ago
cause rm is a native command in every system
skg
skgOPā€¢4mo ago
ig
Want results from more Discord servers?
Add your server