neru
DIAdiscord.js - Imagine an app
•Created by neru on 3/5/2024 in #djs-voice
joinVoiceChannel does absolutely nothing
const { SlashCommandBuilder } = require('discord.js');
const { joinVoiceChannel, getVoiceConnection, entersState, VoiceConnectionStatus } = require('@discordjs/voice');
module.exports = {
data: new SlashCommandBuilder()
.setName('join')
.setDescription('Makes the bot join your voice channel'),
run: async (Interaction) => {
await Interaction.deferReply();
if (!Interaction.member.voice.channel)
return Interaction.editReply('You must be on a Voice channel to run this command.')
var Conn = getVoiceConnection(Interaction.guild.id)
if (!Conn) {
const Options = {
chanelId: Interaction.member.voice.channel.id,
guildId: Interaction.guild.id,
adapterCreator: Interaction.guild.voiceAdapterCreator,
selfDeaf: true,
selfMute: false,
debug: true
};
Conn = joinVoiceChannel(Options);
Conn.on('error', (err) => {
console.log(err);
});
Conn.on('debug', (dbg) => {
console.log(`dbg: ${dbg}`);
});
Conn.on('stateChange', (state, stateNew) => {
console.log(`state: ${state} ${stateNew}`);
});
try {
await entersState(Conn, VoiceConnectionStatus.Ready, 30_000);
} catch(Err) {
return Interaction.editReply(`Connection timed out...`);
}
Interaction.editReply(`Joined`);
}
}
}
const { SlashCommandBuilder } = require('discord.js');
const { joinVoiceChannel, getVoiceConnection, entersState, VoiceConnectionStatus } = require('@discordjs/voice');
module.exports = {
data: new SlashCommandBuilder()
.setName('join')
.setDescription('Makes the bot join your voice channel'),
run: async (Interaction) => {
await Interaction.deferReply();
if (!Interaction.member.voice.channel)
return Interaction.editReply('You must be on a Voice channel to run this command.')
var Conn = getVoiceConnection(Interaction.guild.id)
if (!Conn) {
const Options = {
chanelId: Interaction.member.voice.channel.id,
guildId: Interaction.guild.id,
adapterCreator: Interaction.guild.voiceAdapterCreator,
selfDeaf: true,
selfMute: false,
debug: true
};
Conn = joinVoiceChannel(Options);
Conn.on('error', (err) => {
console.log(err);
});
Conn.on('debug', (dbg) => {
console.log(`dbg: ${dbg}`);
});
Conn.on('stateChange', (state, stateNew) => {
console.log(`state: ${state} ${stateNew}`);
});
try {
await entersState(Conn, VoiceConnectionStatus.Ready, 30_000);
} catch(Err) {
return Interaction.editReply(`Connection timed out...`);
}
Interaction.editReply(`Joined`);
}
}
}
7 replies