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

Bot not joining voice channel and not leaving and error messages #10179

Closed
ttse76 opened this issue Mar 16, 2024 · 0 comments
Closed

Bot not joining voice channel and not leaving and error messages #10179

ttse76 opened this issue Mar 16, 2024 · 0 comments

Comments

@ttse76
Copy link

ttse76 commented Mar 16, 2024

Which package is this bug report for?

voice

Issue description

Apologies if this is not categorized correctly.

I am attempting to build a discord music bot with discordjs. I have previously built music playing bots that have worked completely fine however now the bot is not joining the voice channel. I don't think it's an issue with play-dl since the bot isn't even joining any channel and there are no error messages.

The bot will sometimes also appear offline for a few seconds before coming back online when the user submits a new interaction.

For this, I have designed it where when a user submits a new query, an entry is saved to mongodb that contains information from play-dl, the guildId, and the voiceChannelId. An event is then emitted that retrieves the next item in the queue, creats a voice connection if necessary, then plays the song. I have confirmed that the correct ids are being saved and used. I have also confirmed that the event does fire and the handler is called.

Everything i've read up on the documentation says this should be working however I don't know if i'm just missing something. I've tried all other avenues to find a solution but I haven't found anything that works. Additionally it does not seem to cause an error as there are no error messages and all the logs print.

Code sample

// my client
const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.GuildVoiceStates
  ]
});

// event handler after user submission
events.on(eventNames.PlayNextEvent, async () => {
  logger.logInfo(eventNames.PlayNextEvent);
  const item = await queue.next();
  const guild = client.guilds.cache.get(item.guildId);

  // establish voice channel connection
  if (!VoiceConnection) {
    logger.logInfo(`creating voice connection in guild ${item.guildId} in channel ${item.voiceChannelId}...`);

    // global variable created outside the handler
    VoiceConnection = joinVoiceChannel({
      channelId: item.voiceChannelId,
      guild: guild.id,
      adapterCreator: guild.voiceAdapterCreator,
      selfMute: false,
      debug: true
    });

    VoiceConnection.on('debug', (m) => {
      console.log('Voice Debug:', m);
    });
  }

  const stream = await play.stream(item.info.url);

  if (!stream) {
    logger.logError('stream is null');
    return;
  }

  const resource = createAudioResource(stream.stream, {
    inputType: stream.type
  });

  let discordPlayer = createAudioPlayer({
    behaviors: {
      noSubscriber: NoSubscriberBehavior.Stop
    }
  });
  discordPlayer.play(resource);
  VoiceConnection.subscribe(discordPlayer);
  logger.logInfo(`playing "${item.title}"`);

  VoiceConnection.on('stateChange', (oldState, newState) => {
    console.log(`Connection transitioned from ${oldState.status} to ${newState.status}`);
  });
});

Versions

  • discordjs 14.14.1
  • @discordjs/voice 0.16.1
  • @discordjs/builders 1.7.0
  • node 20.11.1

Issue priority

Medium (should be fixed soon)

Which partials do you have configured?

No Partials

Which gateway intents are you subscribing to?

Guilds, GuildVoiceStates, GuildMessages

I have tested this issue on a development release

No response

@ttse76 ttse76 closed this as completed Mar 16, 2024
@Jiralite Jiralite closed this as not planned Won't fix, can't repro, duplicate, stale Mar 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants