Guest User

Untitled

a guest
Aug 19th, 2021
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. const { Client, Intents, MessageActionRow, MessageButton, Message } = require('discord.js')
  2. const { joinVoiceChannel, createAudioPlayer, createAudioResource, VoiceConnectionStatus, StreamType } = require('@discordjs/voice')
  3. const { join } = require('path')
  4. const { createReadStream } = require('fs')
  5.  
  6. const client = new Client({
  7. intents: [Intents.FLAGS.GUILDS]
  8. })
  9.  
  10. client.once('ready', () => {
  11. console.log('Client ready.')
  12. run()
  13. })
  14.  
  15. client.login('BOT_TOKEN')
  16.  
  17. client.on('debug', console.log)
  18.  
  19. const run = async () => {
  20. const voiceChannel = client.channels.cache.get('CHANNEL_ID')
  21.  
  22. const voiceConnection = joinVoiceChannel({
  23. channelId: voiceChannel.id,
  24. guildId: voiceChannel.guild.id,
  25. adapterCreator: voiceChannel.guild.voiceAdapterCreator,
  26. selfMute: false,
  27. })
  28.  
  29. voiceConnection.on(VoiceConnectionStatus.Connecting, () => { /// not logging
  30. console.log('connected to voice')
  31. })
  32.  
  33. voiceConnection.on(VoiceConnectionStatus.Ready, () => { /// not logging
  34. console.log('ready')
  35. })
  36.  
  37. const player = createAudioPlayer()
  38.  
  39. player.on('error', e => {
  40. console.error('Audio player error', e) /// Not logging
  41. })
  42.  
  43. const resource = createAudioResource(createReadStream(join(__dirname, '/sound.ogg')), {
  44. inputType: StreamType.OggOpus,
  45. })
  46.  
  47. console.log(resource)
  48. player.play(resource)
  49.  
  50. const subscription = voiceConnection.subscribe(player)
  51. }
  52.  
  53. process.on("unhandledRejection", console.error)
Advertisement
Add Comment
Please, Sign In to add comment