Advertisement
DubStepMad

Untitled

Jul 2nd, 2023
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. let images = [
  2. "https://media.giphy.com/media/tjpOYwb6PklO0/giphy.gif",
  3. "https://media.giphy.com/media/YbniyzLEgaJGM/giphy.gif",
  4. "https://media.giphy.com/media/QJTpVVklS5ruU/giphy.gif",
  5. ];
  6. const fetch = require("node-fetch");
  7. const { SlashCommandBuilder } = require("discord.js");
  8. const {
  9. StreamType,
  10. joinVoiceChannel,
  11. createAudioPlayer,
  12. NoSubscriberBehavior,
  13. createAudioResource,
  14. AudioPlayerStatus,
  15. VoiceConnectionStatus,
  16. } = require("@discordjs/voice");
  17.  
  18. module.exports = {
  19. data: new SlashCommandBuilder()
  20. .setName("join-channel")
  21. .setDescription("Makes the bot join the channel"),
  22. async execute(interaction, client) {
  23. const message = await interaction.deferReply({
  24. fetchReply: false,
  25. });
  26.  
  27. const connection = joinVoiceChannel({
  28. channelId: interaction.member.voice.channel.id,
  29. guildId: interaction.guildId,
  30. adapterCreator: interaction.guild.voiceAdapterCreator,
  31. });
  32.  
  33. const resource = createAudioResource(
  34. "https://simulatorfm.stream/radio/8025/radio.mp3",
  35. { inlineVolum: true, type: StreamType.Arbitrary }
  36. );
  37.  
  38. const player = createAudioPlayer({
  39. behaviors: {
  40. noSubscriber: NoSubscriberBehavior.Play,
  41. },
  42. });
  43.  
  44. connection.subscribe(player);
  45. connection.on(VoiceConnectionStatus.Ready, () => {
  46. player.play(resource);
  47. })
  48. connection.on(VoiceConnectionStatus.Disconnected, async (oldState, newState) => {
  49. try {
  50. console.log("Disconnected.")
  51. await Promise.race([
  52. entersState(connection, VoiceConnectionStatus.Signalling, 5_000),
  53. entersState(connection, VoiceConnectionStatus.Connecting, 5_000),
  54. ]);
  55. } catch (error) {
  56. connection.destroy();
  57. }
  58. });
  59. player.on("error", (error) => {
  60. console.error(
  61. `Error: ${error.message} with resource ${error.resource.metadata.title}`
  62. );
  63. player.play(getNextResource());
  64. });
  65.  
  66. player.on(AudioPlayerStatus.Idle, () => {
  67. player.play(getNextResource());
  68. });
  69. },
  70. };
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement