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,
});
} }
} }
42 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 OPyea if you use the library inside a bot context (where you have access to the client at least) you can just programatically join the channels you want. In this case i see you have access to your interaction, and apparently you accept a channel option aswell. If the channel is a voice channel, you can just pass the voiceChannel.id to the channelId: option in the
joinVoiceChannel()
call
i dont know why you didn't do that, you have the voice channel theresee my guildid says his value is intraction.guild.id i also want something like that so my bot automatic peek the value for channel id
yea i am not understading what you want
you say you want your bot to pick a value for the channel id
but how
what channel do you want it to join
in which i am in currently
you can access the channel you are in through the interaction object
interaction.member
is you
member.voice
is your VoiceState
voice.channel.id
is the voice channel Id you are connected tolet me put this value and comeback
its says this error ReferenceError: voice is not defined
at Object.execute (/workspaces/discord-voice/commands/music/join.js:10:24)
at Client.<anonymous> (/workspaces/discord-voice/index.js:40:17)
at Client.emit (node:events:518:28)
at InteractionCreateAction.handle (/workspaces/discord-voice/node_modules/discord.js/src/client/actions/InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (/workspaces/discord-voice/node_modules/discord.js/src/client/websocket/handlers/INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (/workspaces/discord-voice/node_modules/discord.js/src/client/websocket/WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (/workspaces/discord-voice/node_modules/discord.js/src/client/websocket/WebSocketManager.js:239:12)
at WebSocketManager.emit (/workspaces/discord-voice/node_modules/@vladfrangu/async_event_emitter/dist/index.cjs:282:31)
at WebSocketShard.<anonymous> (/workspaces/discord-voice/node_modules/@discordjs/ws/dist/index.js:1173:51)
at WebSocketShard.emit (/workspaces/discord-voice/node_modules/@vladfrangu/async_event_emitter/dist/index.cjs:282:31)
can i ping you @ShompiFlen
yea well you have to access it from the interaction
i can't really just give you the code, thats not the idea here
but i basically gave you the answer
this is not possible see if i put the real channel id something like this "1086434561640108086" then it works but if i try the solution which you game then it wont
all right atleast try one more time
it doesn't because you did it wrong, if you get an error again show me the code
also make sure you have the GuildVoiceStates intent in your client
ohh shit man i forgot the voicestate intnet let me do this again
still the same error ReferenceError: voice is not defined
show your event code
module.exports = {
data: new SlashCommandBuilder()
.setName('join')
.setDescription('join voice channel in which you are'),
async execute(interaction) {
const connection = joinVoiceChannel({
channelId: voice.channel.id,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator,
});
yeah uh
u dont have
voice
definedand how to do that
try something like
channelId: interaction.member.voice.channel.id
access it through the interaction
thats exactly what i was trying to avoid
spoonfeeding
shit sorry š
i already did that wait
so basically u can access the voice object for that member directly from the member object
congo guys new error in same line TypeError: Cannot read properties of null (reading 'id')
that means the member is not in a voice channel
@U j a a n bro if i give it chnnelid like this "1086434561640108086" then it works and other than any thing it wont work the solution you game me i tried but this still error is same
join a vc then try it while u are in the vc
not working
hey big bro help @ShompiFlen
are u sure you're in a vc while using the cmd ???
show me your code again + the error
okey here we go the code
and the error
try logging
interaction.member.voice
holly molly when i run this command /join my bot goes temprary offline oh my god
this thing is something wth
run your bot, disconnect and connect to the voice channel again and run the command
if its still null then there is probably another issue here
show
now even ping command is not working let me take step back and put directly the channel id and try again
dude show me what it logs
sorry bro but now there is nothing in log but my bot goes temprary offline and come back after 3 sec
i tried putting my channel id direct now it working wth
well then log it again tf
ok let me do this again
Ready! Logged in as Craber#3061
thats it man
...
run the cmd
ok
no logs no error but it says application did not respond in my chat
did u not log it ????
.....
i did but there is no error man nothing
thanks for your pations
i will send you dm if it fixes man
@U j a a n it worked you missed one key substanse it should be interaction.member.voice.channelId
you stoped at voice there should be channelid also
congo guys
great
š
thanks man today i can say like elon i never give up š„
thanks @ShompiFlen also good guy see ya