0
votes

My discord.js bot can play music when called within Discord itself, but I have a twitch bot also coded into the same instance. When calling the playcommand through twitch the bot crashes due to there being no channel info, Is there a way I can get a discord user ID's channel info, and have it join that channel instead of crashing due to the voice channel being undefined.

I've tried having the bot join the channel preemptively, tried client.channel.get, tried changing the undefined solving section in the libraries code, and I cannot find anything in the docs.

Snippet handling twitch interaction;

twitch_client.on('chat', (channel, user, message, self) => {
  if (message.startsWith('!play')) {
    song = message.replace(/!play /g, '');
    let channel = discord_client.channels.get('583035488655638528');
    discord_client.channels.get('573327430148947968').send('Sent from Twitch.');
    //channel.join()
    //.then(connection => console.log('Connected'))
    //.catch(console.error);
    discord_client.music.bot.playFunction(song);
  }
});

Discord handling portion is the default discord.js-musicbot-addon

Calls out

\node_modules\discord.js-musicbot-addon\index.js:405 if (msg.member.voiceChannel === undefined) { ^

TypeError: Cannot read property 'voiceChannel' of undefined at Music.musicbot.playFunction (D:\Programming\DiscordTwitchBot\node_modules\discord.js-musicbot-addon\index.js:405:22) at client. (D:\Programming\DiscordTwitchBot\index.js:36:30) at client.EventEmitter.emit (D:\Programming\DiscordTwitchBot\node_modules\tmi.js\lib\events.js:101:25) at client.EventEmitter.emits (D:\Programming\DiscordTwitchBot\node_modules\tmi.js\lib\events.js:64:19) at client.handleMessage (D:\Programming\DiscordTwitchBot\node_modules\tmi.js\lib\client.js:992:34) at D:\Programming\DiscordTwitchBot\node_modules\tmi.js\lib\client.js:1069:36 at Array.forEach () at client._onMessage (D:\Programming\DiscordTwitchBot\node_modules\tmi.js\lib\client.js:1068:11) at WebSocket.onMessage (D:\Programming\DiscordTwitchBot\node_modules\ws\lib\event-target.js:120:16) at WebSocket.emit (events.js:200:13)

1

1 Answers

0
votes

In discord.js-musicbot-addon's playFunction() function, the first parameter is the command message (from Discord), the second is the suffix/URL, and the third is the arguments. In your code, you're just passing song.