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
23 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
- ✅
Marked as resolved by OP:method: VoiceConnection#disconnect()
Disconnects the VoiceConnection, allowing the possibility of rejoining later on.
:method: VoiceConnection#destroy()
Destroys the VoiceConnection, preventing it from connecting to voice again. This method should be called when you no longer require the VoiceConnection to prevent memory leaks.
i did try but i am noob i like spoon fiding can you write the code
thats what you think but
the truth is i am reading this god dam voice docummantaton from last 1 month but i got no idea
please help me
can i ping you @ʎǝɹquoɯ
It would help not to ping while asking if you can, since it's clearly against the rules
maybe read up a bit of js
that'd really help you and everyone else honestly
sorry
i did tried and implement some code so here is the code and error
ReferenceError: Cannot access 'connection' before initialization
Get the voice connection from the server first
const { getVoiceConnection } = require('@discordjs/voice')
getVoiceConnection(interaction.guildId)
https://discord.js.org/docs/packages/voice/0.14.0/getVoiceConnection:Function
I'm just a hobbyist so could 1000% be wrong. the voice documentation is quite confusing and very limited compared to everything else, so I don't blame you for not catching onto it.voice | getVoiceConnection
Finds a voice connection with the given guild id and group. Defaults to the 'default' group.
i tried this wanna see error 😆
Sure
I'm actually making the command now too lol though in my basic testing this worked fine
but you are using newstate function thats diff story cna you show full code
It's the same thing - the guildId
The newState is when a user joins / leaves a vc whereas interaction is the... well interaction. But both values being put in is the guildId so it's the same thing
ok let me see wait h a minute
What error did you get?
wth now i am not getting error bot the command is not working here is the code
const { SlashCommandBuilder } = require('discord.js');
const { getVoiceConnection } = require('@discordjs/voice');
module.exports = {
data: new SlashCommandBuilder()
.setName('leave')
.setDescription('leaves voice channel in which you are'),
async execute(interaction) {
const connection = getVoiceConnection({guildId : interaction.guildId});
if (connection) connection.destroy();
await interaction.reply("the bot has leaved the channel")
} } do you see something wrong
} } do you see something wrong
Yes, why are you doing {guildId : interaction.guildId}
ohh my bad wait
wow man you are genius it worked can you explainme how please
you are a goat
To destroy the connection, you need to tell it what the connection is. getVoiceConnection just says what that connection is. getVoiceConnection provided with a guildId checks to see if the bot is connected in a VC in that guild
man i am so pi*sd now because that goad damm voice documantation s**ks i do not get the did so much good job on rest of guid but like on voice the did nothing
It's a little rough, but it's definitely all there for the most part. Just have to read a little more is all. The documents is not your only guide though. Don't be ashamed to look up on YouTube, GitHub, and simply Google, etc. Just remember to actually learn how it works and not just copy what you see
yes you are right btw i watched every thing what i can lol i am happy now now time to do some work on play command
last thing can you be my friend do not worry i will only dm you when its so important
You don't need to be my friend to dm, just keep in mind I have no obligation to assist or even respond. Probably best to just make a post here
But if I'm not busy, happy to help if I have the knowledge
ofcourse okey here is deal for non cooding friend mean i wont dm you for code just be a friend
time to mark the post as resolved