Buttons Expiring

My buttons expire. I use interaction event to make them permanent but it does not work.
48 Replies
d.js toolkit
d.js toolkit11mo 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! - Marked as resolved by OP
Crocodile
CrocodileOP11mo ago
No description
Crocodile
CrocodileOP11mo ago
Here is my code and what i mean by expiring is that they do not work after restart. No errors. no anything in console.
Ashish
Ashish11mo ago
Any errors?
Crocodile
CrocodileOP11mo ago
Nope. Just they expire when I turn off the bot.
Ashish
Ashish11mo ago
Also, I have a few issues with this code. You have multiple client.on() for the Events.InteractionCreate event, you should only have 1. Use if checks inside the event to figure what each button does
Crocodile
CrocodileOP11mo ago
Alright how do I configure my code to make it like this.
Ashish
Ashish11mo ago
This won't solve the issue, but it will make it better:
client.on(Events.InteractionCreate, async interaction => {
if (interaction.customId === "firstButton") {
// code here
} else if (interaction.customId === "secondButton") {
// other code here
}
})
client.on(Events.InteractionCreate, async interaction => {
if (interaction.customId === "firstButton") {
// code here
} else if (interaction.customId === "secondButton") {
// other code here
}
})
Secondly, does your bot just not reply, or does it not do anything? Like does it create a channel?
Crocodile
CrocodileOP11mo ago
It makes the channel in the specific category it works perfectly fine. It just doesn't stay on after the bot restarts.
Ashish
Ashish11mo ago
Meaning if you restart the bot and press the button, it just says Interaction Failed?
Crocodile
CrocodileOP11mo ago
Yes.
Ashish
Ashish11mo ago
And bot doesn't do anything else as well, is what I understand
Crocodile
CrocodileOP11mo ago
but if I keep the bot on from the start it works. So. I type in ping to make it send the message. It sends and I can use all the buttons.
Ashish
Ashish11mo ago
How fast do you press the button after the bot restarts? Because it might be possible that the bot is still booting up
Crocodile
CrocodileOP11mo ago
I try it like 10 times it doesn't work. Nope. It says it boots up and stuff. It just doesn't stay.
Ashish
Ashish11mo ago
Show me your intents
Crocodile
CrocodileOP11mo ago
require('dotenv').config();
const { Client, IntentsBitField, AuditLogEvent, ButtonBuilder, ButtonStyle, ComponentType, ActionRowBuilder, EmbedBuilder, PermissionsBitField, CommandKit, SlashCommandBuilder, Events } = require('discord.js');
const { mongoose } = require ('mongoose');
const eventHandler = require('./handlers/eventHandler');

const client = new Client({
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.MessageContent,
],
});
require('dotenv').config();
const { Client, IntentsBitField, AuditLogEvent, ButtonBuilder, ButtonStyle, ComponentType, ActionRowBuilder, EmbedBuilder, PermissionsBitField, CommandKit, SlashCommandBuilder, Events } = require('discord.js');
const { mongoose } = require ('mongoose');
const eventHandler = require('./handlers/eventHandler');

const client = new Client({
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.MessageContent,
],
});
These?
Ashish
Ashish11mo ago
Yeah, intents seem fine Where did you initially have the collectors?
Crocodile
CrocodileOP11mo ago
wdym by that?
Ashish
Ashish11mo ago
Can you show me the code where you used collectors before switching to interaction event
Crocodile
CrocodileOP11mo ago
I do not have it anymore. All I have is this.
Ashish
Ashish11mo ago
Do you have the code where you send all the buttons?
Crocodile
CrocodileOP11mo ago
This is all the code for the buttons?
Ashish
Ashish11mo ago
Nevermind ignore me
Crocodile
CrocodileOP11mo ago
Alright.
Ashish
Ashish11mo ago
I'm stumped, I can't seem to find why it does that
Crocodile
CrocodileOP11mo ago
hm
Ashish
Ashish11mo ago
@Crocodile, for the const member = interaction.guild.members.cache.get(interaction.user.id); Change it to const member = interaction.member
Crocodile
CrocodileOP11mo ago
done lemme try It still doesn't work after restart. Here
Crocodile
CrocodileOP11mo ago
No description
Crocodile
CrocodileOP11mo ago
Heres a preview. All the buttons work but then when I restart my bot I get the This Interaction Failed.
Ashish
Ashish11mo ago
That is extremely odd. Just want to confirm, you did save all the files right?
Crocodile
CrocodileOP11mo ago
Yes.
Ashish
Ashish11mo ago
Okay I figured the issue You need to seperate your MessageCreate event and InteractionCreate completely, currently you're nesting them, meaning they only start listening to event once you use the command
Crocodile
CrocodileOP11mo ago
How do I do this?
Ashish
Ashish11mo ago
client.on('messageCreate', async (message) => {
// your code here
}

client.on(Events.InteractionCreate, async (interaction) => {
// code here
}
client.on('messageCreate', async (message) => {
// your code here
}

client.on(Events.InteractionCreate, async (interaction) => {
// code here
}
Crocodile
CrocodileOP11mo ago
And what all would I put in message create?
Ashish
Ashish11mo ago
Your command
Crocodile
CrocodileOP11mo ago
I don't use a command? I use ping
Ashish
Ashish11mo ago
Yeah that's essentially a command
Crocodile
CrocodileOP11mo ago
Meaning if someone says "ping" in chat the embed will summon oh alr so only this?
client.on('messageCreate', async (message) => {
if (message.author.bot) return;

if (message.content !== 'ping') return;
client.on('messageCreate', async (message) => {
if (message.author.bot) return;

if (message.content !== 'ping') return;
Ashish
Ashish11mo ago
Everything below it as well before client.on
Ashish
Ashish11mo ago
Yes
Crocodile
CrocodileOP11mo ago
ReferenceError: message is not defined
at Client.<anonymous> (C:\Users\NotYo\Downloads\Video 2\src\index.js:266:21)
at Client.emit (node:events:526:35)
at InteractionCreateAction.handle (C:\Users\NotYo\Downloads\Video 2\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (C:\Users\NotYo\Downloads\Video 2\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (C:\Users\NotYo\Downloads\Video 2\node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (C:\Users\NotYo\Downloads\Video 2\node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12)
at WebSocketManager.emit (C:\Users\NotYo\Downloads\Video 2\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
at WebSocketShard.<anonymous> (C:\Users\NotYo\Downloads\Video 2\node_modules\@discordjs\ws\dist\index.js:1173:51)
at WebSocketShard.emit (C:\Users\NotYo\Downloads\Video 2\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
at WebSocketShard.onMessage (C:\Users\NotYo\Downloads\Video 2\node_modules\@discordjs\ws\dist\index.js:988:14)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:397:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21)

Node.js v20.10.0
[nodemon] app crashed - waiting for file changes before starting...
ReferenceError: message is not defined
at Client.<anonymous> (C:\Users\NotYo\Downloads\Video 2\src\index.js:266:21)
at Client.emit (node:events:526:35)
at InteractionCreateAction.handle (C:\Users\NotYo\Downloads\Video 2\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (C:\Users\NotYo\Downloads\Video 2\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (C:\Users\NotYo\Downloads\Video 2\node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (C:\Users\NotYo\Downloads\Video 2\node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12)
at WebSocketManager.emit (C:\Users\NotYo\Downloads\Video 2\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
at WebSocketShard.<anonymous> (C:\Users\NotYo\Downloads\Video 2\node_modules\@discordjs\ws\dist\index.js:1173:51)
at WebSocketShard.emit (C:\Users\NotYo\Downloads\Video 2\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
at WebSocketShard.onMessage (C:\Users\NotYo\Downloads\Video 2\node_modules\@discordjs\ws\dist\index.js:988:14)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:397:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21)

Node.js v20.10.0
[nodemon] app crashed - waiting for file changes before starting...
const guild = message.guild;
const guild = message.guild;
This line
Ashish
Ashish11mo ago
Yea change it to interaction.guild
Crocodile
CrocodileOP11mo ago
bro thank you so much it finally works.
Want results from more Discord servers?
Add your server