I get this error when I execute code ,I want to access server_queue playing
TypeError: Cannot read properties of undefined (reading 'playing')
This is my code:
const server_queue = queue.get(interaction.guild.id);
if (!server_queue) {
const server_data = {
queue: [],
connection: null,
dispatcher: null,
playing: false,
}
queue.set(interaction.guild.id, server_data);
server_data.queue.push(url);
}
if (server_queue.playing) {
return interaction.reply("")
}
CodePudding user response:
After skipping your first if
block when server_queue
doesn't exist, you are then trying to access playing
on top of the nonexistent server_queue
. Try adding and else if
block instead of if
to ensure you have it.
const server_queue = queue.get(interaction.guild.id);
if (!server_queue) {
const server_data = {
queue: [],
connection: null,
dispatcher: null,
playing: false,
}
queue.set(interaction.guild.id, server_data);
server_data.queue.push(url);
}
else if (server_queue.playing) {
return interaction.reply("")
}