I am using 'discord.js' v13 library with 'quick.db' npm package.
I am trying to save the channel from the interaction, but when I do it for first time bot sends me that I have already the channel. When I try for a second and third time, it sends me the same message and recreates a channel.
The JavaScript code I am using:
client.on('interactionCreate', async(interaction) => {
if (interaction.customId === "general") {
await interaction.deferUpdate();
const channel = await interaction.guild.channels.create(`name-${interaction.member.user.username}`, {
type: 'GUILD_TEXT'
}).then(async channel => {
const del = new MessageButton()
.setStyle("DANGER")
.setLabel(" Delete")
.setCustomId("del");
const delbut = new MessageActionRow()
.addComponents([
[del]
])
await channel.send({
content: `test`,
embeds: [test],
components: [delbut]
}).catch(e => {
console.log(e.message)
});
const channelID = await interaction.guild.channels.cache.get(channel.id);
const newchannel = await db.set(`channel_${interaction.guild.id}_${interaction.channel.id}`, interaction.member.id)
if (newchannel) {
const savedChannel = await db.get(`channel_${interaction.guild.id}_${interaction.channel.id}`)
interaction.member.send({
content: `Channel: ${channelID}`
})
}
}
})
if (interaction.customId === "del") {
await interaction.deferUpdate();
interaction.message.channel.delete()
}
}
});