Question about Button Interactions

Hello - I have a TempVoice System & Button to Manage on the Embed in the Voice. (Voice Lock & Unlock)
After clicking one Button & re-clicking gives me the "Interaction Error" while clicking again.
No description
37 Replies
d.js toolkit
d.js toolkit•7mo ago
- 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!
duck
duck•7mo ago
could you clarify which 'interaction error' you're referring to? do you mean "Interaction failed" in your discord client? or do you mean some interaction related error in the console?
cRiZZly
cRiZZlyOP•7mo ago
yea interaction failed in the client
cRiZZly
cRiZZlyOP•7mo ago
No description
cRiZZly
cRiZZlyOP•7mo ago
first click on lock -> worked & 2. click -> the interaction failed
duck
duck•7mo ago
well that just means your bot didn't respond to the interaction within 3 seconds if you're not receiving an error in the console and it doesn't successfully unlock the channel, sounds like this code just isn't executing
d.js docs
d.js docs•7mo ago
If you aren't getting any errors, try to place console.log checkpoints throughout your code to find out where execution stops. - Once you do, log relevant values and if-conditions - More sophisticated debugging methods are breakpoints and runtime inspections: learn more
duck
duck•7mo ago
side note: you'll probably want to defer before doing anything that could cause your bot's response to be late (e.g. at least the updateChannelPermissions call, not sure what validateVoiceChannel does)
cRiZZly
cRiZZlyOP•7mo ago
private async validateVoiceChannel(
voiceChannel: VoiceChannel,
member: GuildMember,
interaction: ButtonInteraction
): Promise<boolean> {
if (!createdChannels.has(voiceChannel.id)) {
await interaction.reply({
content: "You must be in a temporary voice channel to use this button.",
flags: 64,
});
return false;
}
if (voiceChannel.name !== `${member.displayName}'s Channel`) {
await interaction.reply({
content: "You can only modify a voice channel that you created.",
flags: 64,
});
return false;
}
return true;
}
private async validateVoiceChannel(
voiceChannel: VoiceChannel,
member: GuildMember,
interaction: ButtonInteraction
): Promise<boolean> {
if (!createdChannels.has(voiceChannel.id)) {
await interaction.reply({
content: "You must be in a temporary voice channel to use this button.",
flags: 64,
});
return false;
}
if (voiceChannel.name !== `${member.displayName}'s Channel`) {
await interaction.reply({
content: "You can only modify a voice channel that you created.",
flags: 64,
});
return false;
}
return true;
}
duck
duck•7mo ago
probably after that then
cRiZZly
cRiZZlyOP•7mo ago
private async updateChannelPermissions(
voiceChannel: VoiceChannel,
guild: Guild,
lock: boolean
) {
const everyoneRole = guild.roles.everyone;
await voiceChannel.permissionOverwrites.edit(everyoneRole, {
Connect: !lock,
});
}
}
private async updateChannelPermissions(
voiceChannel: VoiceChannel,
guild: Guild,
lock: boolean
) {
const everyoneRole = guild.roles.everyone;
await voiceChannel.permissionOverwrites.edit(everyoneRole, {
Connect: !lock,
});
}
}
And thats the updateChannelPermissions @duck When i change this Code:
private async updateChannelPermissions(
voiceChannel: VoiceChannel,
guild: Guild,
lock: boolean
) {
const memberRole = guild.roles.cache.get(DISCORD_ROLES.MEMBER);
if (!memberRole) {
throw new Error("The player role could not be found.");
}
await voiceChannel.permissionOverwrites.edit(memberRole, {
Connect: !lock,
});
}
}
private async updateChannelPermissions(
voiceChannel: VoiceChannel,
guild: Guild,
lock: boolean
) {
const memberRole = guild.roles.cache.get(DISCORD_ROLES.MEMBER);
if (!memberRole) {
throw new Error("The player role could not be found.");
}
await voiceChannel.permissionOverwrites.edit(memberRole, {
Connect: !lock,
});
}
}
to this code:
private async updateChannelPermissions(
voiceChannel: VoiceChannel,
guild: Guild,
lock: boolean
) {
const everyoneRole = guild.roles.everyone;

await voiceChannel.permissionOverwrites.edit(everyoneRole, {
Connect: !lock,
});
}
}
private async updateChannelPermissions(
voiceChannel: VoiceChannel,
guild: Guild,
lock: boolean
) {
const everyoneRole = guild.roles.everyone;

await voiceChannel.permissionOverwrites.edit(everyoneRole, {
Connect: !lock,
});
}
}
its not working
duck
duck•7mo ago
I'm not sure what this change has to do with what I said ^
cRiZZly
cRiZZlyOP•7mo ago
I mean its working again with the other code but when i change this its stop working without errors
cRiZZly
cRiZZlyOP•7mo ago
No description
cRiZZly
cRiZZlyOP•7mo ago
thats a weird thing
duck
duck•7mo ago
if you really believe this change to be related to the issue, I would still suggest logging throughout the point is to see where execution stops in the absence of an error
cRiZZly
cRiZZlyOP•7mo ago
Okay i will log everything and will execute the system
[handleVoiceStateUpdate] newChannelId: 1371243088219209778
[handleVoiceStateUpdate] oldChannelId: null
[shouldCreateNewChannel] {
newChannelId: '1371243088219209778',
oldChannelId: null,
result: true
}
[handleVoiceStateUpdate] Creating new channel...
[createNewVoiceChannel] Start creating channel for 777
[createNewVoiceChannel] Created channel: 1372709248181731328
[createNewVoiceChannel] Added to createdChannels: 1372709248181731328
[createNewVoiceChannel] Sent embed and buttons
[handleVoiceStateUpdate] Guild: 🦎 Lizard - Official Discord
[handleVoiceStateUpdate] newChannelId: 1372709248181731328
[handleVoiceStateUpdate] oldChannelId: 1371243088219209778
[shouldCreateNewChannel] {
newChannelId: '1372709248181731328',
oldChannelId: '1371243088219209778',
result: false
}
[shouldDeleteOldChannel] { oldChannelId: '1371243088219209778', result: false }
[createNewVoiceChannel] Moved member to new channel
[createNewVoiceChannel] Setting channel permissions
[setChannelPermissions] Setting permissions for channel 1372709248181731328
[setChannelPermissions] Permissions set
[shouldDeleteOldChannel] { oldChannelId: null, result: false }
[handleVoiceLock] Button pressed by supersayajin7
[validateVoiceChannel] Checking channel 1372709248181731328
[updateChannelPermissions] Setting Connect permission to false on channel 1372709248181731328
[updateChannelPermissions] Permissions updated
[handleVoiceLock] Channel locked
[handleVoiceUnlock] Button pressed by supersayajin7
[validateVoiceChannel] Checking channel 1372709248181731328
[updateChannelPermissions] Setting Connect permission to true on channel 1372709248181731328
[updateChannelPermissions] Permissions updated
[handleVoiceUnlock] Channel unlocked
[handleVoiceStateUpdate] newChannelId: 1371243088219209778
[handleVoiceStateUpdate] oldChannelId: null
[shouldCreateNewChannel] {
newChannelId: '1371243088219209778',
oldChannelId: null,
result: true
}
[handleVoiceStateUpdate] Creating new channel...
[createNewVoiceChannel] Start creating channel for 777
[createNewVoiceChannel] Created channel: 1372709248181731328
[createNewVoiceChannel] Added to createdChannels: 1372709248181731328
[createNewVoiceChannel] Sent embed and buttons
[handleVoiceStateUpdate] Guild: 🦎 Lizard - Official Discord
[handleVoiceStateUpdate] newChannelId: 1372709248181731328
[handleVoiceStateUpdate] oldChannelId: 1371243088219209778
[shouldCreateNewChannel] {
newChannelId: '1372709248181731328',
oldChannelId: '1371243088219209778',
result: false
}
[shouldDeleteOldChannel] { oldChannelId: '1371243088219209778', result: false }
[createNewVoiceChannel] Moved member to new channel
[createNewVoiceChannel] Setting channel permissions
[setChannelPermissions] Setting permissions for channel 1372709248181731328
[setChannelPermissions] Permissions set
[shouldDeleteOldChannel] { oldChannelId: null, result: false }
[handleVoiceLock] Button pressed by supersayajin7
[validateVoiceChannel] Checking channel 1372709248181731328
[updateChannelPermissions] Setting Connect permission to false on channel 1372709248181731328
[updateChannelPermissions] Permissions updated
[handleVoiceLock] Channel locked
[handleVoiceUnlock] Button pressed by supersayajin7
[validateVoiceChannel] Checking channel 1372709248181731328
[updateChannelPermissions] Setting Connect permission to true on channel 1372709248181731328
[updateChannelPermissions] Permissions updated
[handleVoiceUnlock] Channel unlocked
This is with the working code without changing the hardcoded member role now i will do with the dynamic guild everyone roleid
[handleVoiceStateUpdate] newChannelId: 1371243088219209778
[handleVoiceStateUpdate] oldChannelId: null
[shouldCreateNewChannel] {
newChannelId: '1371243088219209778',
oldChannelId: null,
result: true
}
[handleVoiceStateUpdate] Creating new channel...
[createNewVoiceChannel] Start creating channel for 777
[createNewVoiceChannel] Created channel: 1372709942846558308
[createNewVoiceChannel] Added to createdChannels: 1372709942846558308
[createNewVoiceChannel] Sent embed and buttons
[handleVoiceStateUpdate] Guild: 🦎 Lizard - Official Discord
[handleVoiceStateUpdate] newChannelId: 1372709942846558308
[handleVoiceStateUpdate] oldChannelId: 1371243088219209778
[shouldCreateNewChannel] {
newChannelId: '1372709942846558308',
oldChannelId: '1371243088219209778',
result: false
}
[shouldDeleteOldChannel] { oldChannelId: '1371243088219209778', result: false }
[createNewVoiceChannel] Moved member to new channel
[createNewVoiceChannel] Setting channel permissions
[setChannelPermissions] Setting permissions for channel 1372709942846558308
[setChannelPermissions] Permissions set
[shouldDeleteOldChannel] { oldChannelId: null, result: false }
[handleVoiceLock] Button pressed by supersayajin7
[validateVoiceChannel] Checking channel 1372709942846558308
[updateChannelPermissions] Setting Connect permission to false on channel 1372709942846558308
[updateChannelPermissions] Permissions updated
[handleVoiceLock] Channel locked
[handleVoiceStateUpdate] newChannelId: 1371243088219209778
[handleVoiceStateUpdate] oldChannelId: null
[shouldCreateNewChannel] {
newChannelId: '1371243088219209778',
oldChannelId: null,
result: true
}
[handleVoiceStateUpdate] Creating new channel...
[createNewVoiceChannel] Start creating channel for 777
[createNewVoiceChannel] Created channel: 1372709942846558308
[createNewVoiceChannel] Added to createdChannels: 1372709942846558308
[createNewVoiceChannel] Sent embed and buttons
[handleVoiceStateUpdate] Guild: 🦎 Lizard - Official Discord
[handleVoiceStateUpdate] newChannelId: 1372709942846558308
[handleVoiceStateUpdate] oldChannelId: 1371243088219209778
[shouldCreateNewChannel] {
newChannelId: '1372709942846558308',
oldChannelId: '1371243088219209778',
result: false
}
[shouldDeleteOldChannel] { oldChannelId: '1371243088219209778', result: false }
[createNewVoiceChannel] Moved member to new channel
[createNewVoiceChannel] Setting channel permissions
[setChannelPermissions] Setting permissions for channel 1372709942846558308
[setChannelPermissions] Permissions set
[shouldDeleteOldChannel] { oldChannelId: null, result: false }
[handleVoiceLock] Button pressed by supersayajin7
[validateVoiceChannel] Checking channel 1372709942846558308
[updateChannelPermissions] Setting Connect permission to false on channel 1372709942846558308
[updateChannelPermissions] Permissions updated
[handleVoiceLock] Channel locked
after clicking at unlock -> interaction failed and no error but when i try to click the buttons via my main discord account it logs me this: [handleVoiceUnlock] Button pressed by .crizzly [validateVoiceChannel] Checking channel 1372709942846558308 [validateVoiceChannel] User does not own this channel: 777's Channel vs cRiZZly's Channel [handleVoiceUnlock] Validation failed and when im on my 2nd acc try to click the buttons its not working and it fails on interaction failed
duck
duck•7mo ago
I don't need to see the logs I can't tell where execution stops just from looking at these since I don't know where in your code you added these logs they're for you to see where execution stops though it also doesn't seem like you added any logs before the code that I mentioned doesn't execute
cRiZZly
cRiZZlyOP•7mo ago
i smell a browser issue
duck
duck•7mo ago
I'm not really sure what this has to do with browsers
cRiZZly
cRiZZlyOP•7mo ago
me either but i dont get it why in my discord client is working but in the browser not where im logged in via my 2nd acc testing it
cRiZZly
cRiZZlyOP•7mo ago
No description
cRiZZly
cRiZZlyOP•7mo ago
left client right browser
duck
duck•7mo ago
if you'd like to continue investigating these other ideas for what the issue could be, go ahead but I won't be helping if you're not willing to read what I say
cRiZZly
cRiZZlyOP•7mo ago
i found the issue If i lock the channel (disable connect), i dont have the permissions anymore for the chat and if i click on the interaction aka voice unlock cuz i still have the chat open the interaction fails But how should i make the logic for that? If i cant connect aka when i lock the channel i dont have access on the chat anymore
duck
duck•7mo ago
admittedly I'm curious as to why discord doesn't have a separate error for that or whether your previous code was working at all if it was also denying the same permission but putting that aside, you could always specifically grant the user that permission since you'd be updating multiple overwrites at the same time, you'll want to use <VoiceChannel>.permissionOverwrites.set() instead of ...edit()
cRiZZly
cRiZZlyOP•7mo ago
okay will use
cRiZZly
cRiZZlyOP•7mo ago
No description
cRiZZly
cRiZZlyOP•7mo ago
like this right
duck
duck•7mo ago
I mean if you really want to also allow those permissions, sure but also you missed the important part
you could always specifically grant the user that permission
cRiZZly
cRiZZlyOP•7mo ago
The thing is, how do I do that, if I block the connection perm, then I no longer have access to the text chat, that's just the problem why the interaction fails
duck
duck•7mo ago
you could always specifically grant the user that permission
cRiZZly
cRiZZlyOP•7mo ago
ah yea forgot to read that part but then its bad for the other people in the vc no? should i make then all user from the vc in? and if they leave -> remove? cuz example: me as owner i lock the channel -> still have access to the chat: example sending a yt video in chat but the other cant see the chat
duck
duck•7mo ago
that's entirely up to you you get to decide how your bot behaves
cRiZZly
cRiZZlyOP•7mo ago
but what is the best practise? im a nearly beginner and dont know whats the best but i still wanna make that good
duck
duck•7mo ago
this isn't really a matter of best practice or not it's the actual behavior, so it's completely up to you to decide also it's not as if you can't change the code later if you change your mind
cRiZZly
cRiZZlyOP•7mo ago
yea i see, thank you very much still wondering why it didnt gave me an error and i needed to activate my braincells to see mhmm i cant access the chat & then i calculated 1+1 😂

Did you find this page helpful?