Toothless
Toothless
DIAdiscord.js - Imagine a bot
Created by Toothless on 2/27/2024 in #djs-questions
how to create /leave command i know how to write /join command
here is the code for join i wan t leave command same like join command
const { SlashCommandBuilder } = require('discord.js');
const { joinVoiceChannel } = require('@discordjs/voice');

module.exports = {
data: new SlashCommandBuilder()
.setName('join')
.setDescription('join voice channel in which you are'),
async execute(interaction) {
const connection = joinVoiceChannel({
channelId: interaction.member.voice.channelId,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator,
});
await interaction.reply("joined your voice channel")


}
}
const { SlashCommandBuilder } = require('discord.js');
const { joinVoiceChannel } = require('@discordjs/voice');

module.exports = {
data: new SlashCommandBuilder()
.setName('join')
.setDescription('join voice channel in which you are'),
async execute(interaction) {
const connection = joinVoiceChannel({
channelId: interaction.member.voice.channelId,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator,
});
await interaction.reply("joined your voice channel")


}
}
35 replies
DIAdiscord.js - Imagine a bot
Created by Toothless on 2/26/2024 in #djs-questions
how to know the channel id of voice channel so that i do not need to put my channel id manually
in my code while using joinvoicechannel function it asks for channel id is there any way so that i do not need to put my id mannually see the code for refrence const { SlashCommandBuilder } = require('discord.js'); const { joinVoiceChannel } = require('@discordjs/voice'); module.exports = { data: new SlashCommandBuilder() .setName('join') .setDescription('join voice channel in which you are'), async execute(interaction) { const voiceChannel = interaction.options.getChannel('channel') const connection = joinVoiceChannel({ channelId: "1086434561640108086", guildId: interaction.guild.id, adapterCreator: interaction.guild.voiceAdapterCreator, });
} }
76 replies
DIAdiscord.js - Imagine a bot
Created by Toothless on 2/24/2024 in #djs-voice
can you simplify the voice connection and how to connect the bot to voice channel i suffered very
help
8 replies
DIAdiscord.js - Imagine a bot
Created by Toothless on 11/21/2023 in #djs-voice
NO CONNECTION TO VOICE CHANNEL
client.on('messageCreate', async (message) => {
if (message.author.bot) return;

if (message.content.toLowerCase() === '!join') {
// Check if the author is in a voice channel
if (!message.member.voice.channel) {
message.reply('You need to be in a voice channel to use this command!');
return;
}

// Join the user's voice channel
const channel = message.member.voice.channel;
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
});

message.reply(`Joined ${channel.name}`);

// You can add additional functionality here, such as playing music, etc.
// For now, let's just log when the bot leaves the channel.

connection.on('stateChange', (state) => {
console.log(`Connection state change: ${state.status}`);
if (state.status === 'Disconnected') {
console.log('Left the channel');
}
});
}
});
client.on('messageCreate', async (message) => {
if (message.author.bot) return;

if (message.content.toLowerCase() === '!join') {
// Check if the author is in a voice channel
if (!message.member.voice.channel) {
message.reply('You need to be in a voice channel to use this command!');
return;
}

// Join the user's voice channel
const channel = message.member.voice.channel;
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
});

message.reply(`Joined ${channel.name}`);

// You can add additional functionality here, such as playing music, etc.
// For now, let's just log when the bot leaves the channel.

connection.on('stateChange', (state) => {
console.log(`Connection state change: ${state.status}`);
if (state.status === 'Disconnected') {
console.log('Left the channel');
}
});
}
});
2 replies