Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Client, Events, GatewayIntentBits, REST, Routes } from 'discord.js';
- import { createAudioPlayer, NoSubscriberBehavior, generateDependencyReport, joinVoiceChannel, getVoiceConnection, createAudioResource } from '@discordjs/voice';
- import config from '../config.json' assert {type: 'json'};
- import path from 'path';
- import * as url from 'url';
- const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
- console.log(generateDependencyReport());
- const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates] });
- const player = createAudioPlayer({
- behaviors: {
- noSubscriber: NoSubscriberBehavior.Pause,
- },
- });
- client.once(Events.ClientReady, c => {
- console.log(`Ready! Logged in as ${c.user.tag}`);
- });
- client.on(Events.InteractionCreate, async interaction => {
- if(interaction.commandName === 'join') {
- const connection = joinVoiceChannel({
- channelId: interaction.channelId,
- guildId: interaction.guildId,
- adapterCreator: interaction.guild.voiceAdapterCreator,
- });
- connection.subscribe(player);
- }
- if(interaction.commandName === 'leave') {
- const connection = getVoiceConnection(interaction.guildId);
- connection.destroy();
- }
- if(interaction.commandName === 'test') {
- const resource = createAudioResource(path.join(__dirname, "test.mp3"));
- player.play(resource);
- }
- interaction.reply('test')
- });
- const rest = new REST().setToken(config.token);
- rest.put(
- Routes.applicationCommands(config.appId),
- { body: [
- {"name": "join", "type": 1, "description": "join"},
- {"name": "test", "type": 1, "description": "test"},
- {"name": "leave", "type": 1, "description": "leave"}] },
- )
- client.login(config.token);
Advertisement
Add Comment
Please, Sign In to add comment