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

getVoiceConnection sometimes return wrong channel #9707

Closed
AlexInCube opened this issue Jul 13, 2023 · 3 comments
Closed

getVoiceConnection sometimes return wrong channel #9707

AlexInCube opened this issue Jul 13, 2023 · 3 comments

Comments

@AlexInCube
Copy link

Which package is this bug report for?

voice

Issue description

I'm trying to do a check to see if the person requesting the command is in a voice channel with the bot. But when I have the bot running for about ~20 hours, getVoiceConnection starts returning the channel the bot was once on a long time ago, not the channel it's currently on.

Steps to reproduce:
I don`t know how to reproduce. I can guess that this is due to packet loss at some point and the "map" where voiceConnection is stored is not cleared.

Code sample

export function checkBotInVoice(guild: Guild): VoiceConnection | undefined{
    return getVoiceConnection(guild.id)
}

export async function checkMemberInVoiceWithBot(member: GuildMember): Promise<{ errorMessage: string; channelTheSame: boolean }> {
    const response = {
        channelTheSame: false,
        errorMessage: "CheckingVoiceError"
    }

    const connection = checkBotInVoice(member.guild)
    if (connection) {
        if (member.voice.channel) {
            response.channelTheSame = connection.joinConfig.channelId === member.voice?.channel.id
            if (response.channelTheSame){
                return response
            }
        }else{
            response.errorMessage = i18next.t("commandshandlers:voice_join_in_any_channel")
            return response
        }

        await member.guild.client.channels.fetch(connection.joinConfig.channelId!).then(channel => {
            if (channel) {
                if (channel instanceof VoiceChannel) {
                    response.errorMessage = `${i18next.t("commandshandlers:voice_join_in_channel")} ${channel.name}`
                }
            }
        })
    }

    return response
}

Versions

  • discord.js 16.11.0
  • node.js 20.2.0
  • typescript 5.1.6

Issue priority

Medium (should be fixed soon)

Which partials do you have configured?

User, Channel, GuildMember, Message

Which gateway intents are you subscribing to?

Guilds, GuildMembers, GuildVoiceStates, GuildPresences, GuildMessages, DirectMessages, DirectMessageTyping, MessageContent

I have tested this issue on a development release

No response

@AlexInCube
Copy link
Author

Maybe i can fetch voiceConnection directly from Discord? like message.fetch or guild.fetch?

@Qjuh
Copy link
Contributor

Qjuh commented Jul 15, 2023

The VoiceConnection is the right one. Your assumption of <VoiceConnection>.joinConfig.channelId being the channel the bot currently is in is wrong though. It‘s the channelId used to initially connect/join.
To find the channel the bot currently is in you‘d simply use <Guild>.members.me.voice.channelId.

@AlexInCube
Copy link
Author

I've already realized that I have to go through members.me.voice.

@Jiralite Jiralite closed this as not planned Won't fix, can't repro, duplicate, stale Jul 16, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants