#Way to get bot to join a voice channel with prebuilt framework

30 messages · Page 1 of 1 (latest)

earnest flax
#

I have a Discord Bot currently, prebuilt although I am not sure on how to get it to join a voice channel and produce audio.

#

(There's no particular code that can represent this) (New as well to JS)

dusky panther
earnest flax
#

I got it from GitHub

#

*I didn’t

#

Someone else did when I tried creating the bot and I got assistance doing so

finite finch
#
let userVoiceChannel = message.member.voice.channel;
console.log(userVoiceChannel.id);
if (userVoiceChannel == null) {
    message.channel.send("You must be in voice channel");
    break;
}

userVoiceChannel.join().then(connection => {
    console.log(client.voice.connections);
    let stream = null
    let dispatcher = null
    try {
        stream = discordTTS.getVoiceStream(textToSpeak, lang);
        dispatcher = connection.play(stream);
    } catch (error) {
        console.log(error);
        userVoiceChannel.leave()
    }
    dispatcher.on("finish",()=>userVoiceChannel.leave())
}).catch(error => message.channel.send("Looks like i don't have the rights"))

https://www.npmjs.com/package/discord-tts

#

I did this in "message" event handler

earnest flax
#

I use the await or const

#

Not “if” variables

finite finch
#

You haven't seen "if" before?

earnest flax
#

I'll share a sample of the code I currently have just to get an understanding of what I'm trying to say.

#
const { MessageActionRow, MessageButton, MessageEmbed } = require("discord.js");

module.exports = {
    name: "startup",
    category: "staff",
    description: "This is the Startup Command for Sessions. | Only to be used in Startup Channels",
    ownerOnly: false,
    run: async (client, interaction) => {
        const msg = await interaction.reply({content: `One moment ${interaction.user}....`, ephemeral: true})
        await interaction.channel.send(`@everyone`);
        let message = await interaction.channel.send```
#

this is just a portion of an embed message

#

although these are some of the variables ive seen

#

not if variables

#

will it work still?

finite finch
#

?

dusky panther
#

what's an "if variable"?

earnest flax
#

what i mean

dusky panther
#

so basically you don't know how to program?

earnest flax
#

I do, I just don't use "if" in my code.

#

I use const to knowledge

dusky panther
#

....wat? if is one of the most basic constructs in any programming language in this world. How do you not use it?

earnest flax
#

That's why I'm concerned, last time I tried it with "if" it said it wasn't recognized and couldn't be pushed out to commands.

finite finch
#

So... Uh... You don't check for variables to be defined? You'd just call join() on null?

dusky panther
#

okay, so you don't know how to code. I recommend checking #faq
It also has some resources on how to approach Discord bots.