Guest User

Untitled

a guest
Sep 24th, 2023
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Client, Events, GatewayIntentBits, REST, Routes } from 'discord.js';
  2. import { createAudioPlayer, NoSubscriberBehavior, generateDependencyReport, joinVoiceChannel, getVoiceConnection, createAudioResource } from '@discordjs/voice';
  3. import config from '../config.json' assert {type: 'json'};
  4. import path from 'path';
  5.  
  6. import * as url from 'url';
  7. const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
  8.  
  9. console.log(generateDependencyReport());
  10.  
  11. const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates] });
  12.  
  13. const player = createAudioPlayer({
  14.     behaviors: {
  15.         noSubscriber: NoSubscriberBehavior.Pause,
  16.     },
  17. });
  18.  
  19. client.once(Events.ClientReady, c => {
  20.     console.log(`Ready! Logged in as ${c.user.tag}`);
  21. });
  22.  
  23. client.on(Events.InteractionCreate, async interaction => {
  24.     if(interaction.commandName === 'join') {
  25.         const connection = joinVoiceChannel({
  26.             channelId: interaction.channelId,
  27.             guildId: interaction.guildId,
  28.             adapterCreator: interaction.guild.voiceAdapterCreator,
  29.         });
  30.    
  31.         connection.subscribe(player);
  32.     }
  33.  
  34.     if(interaction.commandName === 'leave') {
  35.         const connection = getVoiceConnection(interaction.guildId);
  36.                 connection.destroy();
  37.     }
  38.  
  39.     if(interaction.commandName === 'test') {
  40.         const resource = createAudioResource(path.join(__dirname, "test.mp3"));
  41.         player.play(resource);
  42.     }
  43.  
  44.     interaction.reply('test')
  45. });
  46.  
  47. const rest = new REST().setToken(config.token);
  48. rest.put(
  49.     Routes.applicationCommands(config.appId),
  50.     { body: [
  51.         {"name": "join", "type": 1, "description": "join"},
  52.         {"name": "test", "type": 1, "description": "test"},
  53.         {"name": "leave", "type": 1, "description": "leave"}] },
  54. )
  55.  
  56. client.login(config.token);
Advertisement
Add Comment
Please, Sign In to add comment