Rei-x / discord-speech-recognition

Speech to text extension for discord.js
https://npmjs.com/package/discord-speech-recognition
MIT License
56 stars 22 forks source link

Doesn't work when using other library for connecting to voice channel #47

Closed Sparoney closed 1 year ago

Sparoney commented 1 year ago

Hi, I am attempting to make a speech recognition music bot with Discord.js v14 and discord-music-player.

I did notice you already made a bot using Discord.js v13.

My code to join the voice channel is the following:

const queue = interaction.client.player.createQueue(channel.guild.id);
queue.join(channel);

This code is the same as the one you are using in your bot (although I am using slash commands) and what is required.

The issue I am facing is if the bot joins the voice channel using queue.join from discord-music-player, the speech recognition does not work. However if the bot joins the voice channel using joinVoiceChannel from discord.js/voice, speech recognition does work.

joinVoiceChannel({
    channelId: channel.id,
    guildId: channel.guild.id,
    adapterCreator: channel.guild.voiceAdapterCreator,
    selfDeaf: false,
});

I am not sure if something has changed between discord.js v13 and v14 and the updates to discord.js/voice and discord-music-player, and was not sure if this is a bug with either of those.

Is it possible to be able get the voice connection from discord-music-player via queue.connection instead of discord.js/voice to start the speech recognition?

Thanks! Sorry if this isn't something you can fix I wasn't sure where to post this issue but considering you had done this before with your own bot I thought I'd ask.

Rei-x commented 1 year ago

Hi, thanks for opening the issue!

The reason why discord-speech-recognition can't detect joining voice channel is because it probably uses different version of @discordjs/voice than discord-music-player.

To fix this issue install @discordjs/voice in version 0.11.0 (the one used by discord-music-player), or if you don't need it uninstall it completely.

In short, run this if you don't need to use @discordjs/voice (i.e. you don't import it in your files)

npm uninstall @discordjs/voice

Run this if you are using @discordjs/voice

npm install @discordjs/voice@0.11.0


I also updated my music bot so you can get inspiration from here.

Sparoney commented 1 year ago

You are amazing thank you! Uninstalling @discordjs/voice fixed it! It was doing my head in trying to figure out why it just wouldn't work.

One other question though, is client.on('speech') able to be modified with event handlers being in separate files? Like how client.on('ready') is now Events.ClientReady.

Thanks!

Rei-x commented 1 year ago

You are amazing thank you! Uninstalling @discordjs/voice fixed it! It was doing my head in trying to figure out why it just wouldn't work.

One other question though, is client.on('speech') able to be modified with event handlers being in separate files? Like how client.on('ready') is now Events.ClientReady.

Thanks!

Now you can use SpeechEvents.speech instead of speech