js
const { ActionRowBuilder, ButtonBuilder, ButtonStyle, Events, Client, GatewayIntentBits, Partials, Collection, ActivityType, SelectMenuBuilder } = require("discord.js");
const { createReadStream } = require('node:fs');
const { join } = require('node:path');
const { AudioPlayerStatus, StreamType, createAudioResource, createAudioPlayer } = require('@discordjs/voice');
const { joinVoiceChannel, getVoiceConnection } = require('@discordjs/voice');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMessages,
],
partials: [
Partials.Channel,
Partials.Message,
Partials.User,
Partials.GuildMember,
],
});
// list of sounds to play
//use always "./files" like this
const sounds = [
'./audio1.mp3',
'./audio2.mp3',
'./audio3.mp3'
];
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
console.log(client.channels);
});
client.on('messageCreate', async message => {
if (message.content === '!play') {
// check if bot is in a voice channel
const channel = client.channels.cache.find(c => c.name === "ăťvcăť");
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
selfDeaf: false,
selfMute: false // this may also
});
const player = createAudioPlayer();
// pick a random sound to play
const sound = sounds[Math.floor(Math.random() * sounds.length)];
// Thanks