Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { Client, Intents, MessageActionRow, MessageButton, Message } = require('discord.js')
- const { joinVoiceChannel, createAudioPlayer, createAudioResource, VoiceConnectionStatus, StreamType } = require('@discordjs/voice')
- const { join } = require('path')
- const { createReadStream } = require('fs')
- const client = new Client({
- intents: [Intents.FLAGS.GUILDS]
- })
- client.once('ready', () => {
- console.log('Client ready.')
- run()
- })
- client.login('BOT_TOKEN')
- client.on('debug', console.log)
- const run = async () => {
- const voiceChannel = client.channels.cache.get('CHANNEL_ID')
- const voiceConnection = joinVoiceChannel({
- channelId: voiceChannel.id,
- guildId: voiceChannel.guild.id,
- adapterCreator: voiceChannel.guild.voiceAdapterCreator,
- selfMute: false,
- })
- voiceConnection.on(VoiceConnectionStatus.Connecting, () => { /// not logging
- console.log('connected to voice')
- })
- voiceConnection.on(VoiceConnectionStatus.Ready, () => { /// not logging
- console.log('ready')
- })
- const player = createAudioPlayer()
- player.on('error', e => {
- console.error('Audio player error', e) /// Not logging
- })
- const resource = createAudioResource(createReadStream(join(__dirname, '/sound.ogg')), {
- inputType: StreamType.OggOpus,
- })
- console.log(resource)
- player.play(resource)
- const subscription = voiceConnection.subscribe(player)
- }
- process.on("unhandledRejection", console.error)
Advertisement
Add Comment
Please, Sign In to add comment