Advertisement
Bacon_Fixation

channelHandler.ts

Jun 9th, 2022 (edited)
1,219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import type { Queue } from './../queue/Queue';
  2. import type { AnyChannel, GuildMember } from 'discord.js';
  3.  
  4. export async function manageStageChannel(
  5.   voiceChannel: AnyChannel,
  6.   botUser: GuildMember,
  7.   instance: Queue
  8. ) {
  9.   if (voiceChannel.type !== 'GUILD_STAGE_VOICE') return;
  10.   // Stage Channel Permissions From Discord.js Doc's
  11.   if (
  12.     !botUser?.permissions.has(
  13.       ('MANAGE_CHANNELS' && 'MUTE_MEMBERS' && 'MOVE_MEMBERS') || 'ADMINISTRATOR'
  14.     )
  15.   )
  16.     if (botUser.voice.suppress)
  17.       return await instance.getTextChannel().then(msg =>
  18.         msg?.send({
  19.           content: `:interrobang: Please make promote me to a Speaker in ${voiceChannel.name}, Missing permissions "Administrator" ***OR*** "Manage Channels, Mute Members, and Move Members" for Full Stage Channel Features.`
  20.         })
  21.       );
  22.   const tracks = await instance.tracks();
  23.   const title =
  24.     instance.player.trackData?.title.length! > 114
  25.       ? `🎶 ${
  26.           instance.player.trackData?.title.slice(0, 114) ??
  27.           tracks.at(0)?.title.slice(0, 114)
  28.         }...`
  29.       : `🎶 ${instance.player.trackData?.title ?? tracks.at(0)?.title}`;
  30.  
  31.   if (!voiceChannel.stageInstance) {
  32.     await voiceChannel
  33.       .createStageInstance({
  34.         topic: title,
  35.         privacyLevel: 2 // Guild Only
  36.       })
  37.       .catch(error => {
  38.         console.log('Failed to Create a Stage Instance.', error);
  39.       });
  40.   }
  41.  
  42.   if (botUser?.voice.suppress)
  43.     await botUser?.voice.setSuppressed(false).catch((error: string) => {
  44.       console.log('Failed to Set Suppressed to False.', error);
  45.     });
  46.   if (voiceChannel.stageInstance?.topic.startsWith('🎶')) {
  47.     await voiceChannel.stageInstance?.setTopic(title).catch(error => {
  48.       console.log('Failed to Set Topic.', error);
  49.     });
  50.   }
  51.   return;
  52. }
  53.  
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement