- What's your exact discord.js
npm list discord.jsand nodenode -vversion? - Not a discord.js issue? Check out #1081585952654360687.
- 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!
#After restarting Buttons dosen't work
57 messages · Page 1 of 1 (latest)
??
By using the interactionCreate event rather than collectors
can you send me link of doc
to see how to use it
(event) Client#interactionCreate
Emitted when an interaction is created.
client.on('interactionCreate', async interaction => {
Should i use this ?
yes
Show your code then
client.on('interactionCreate', async interaction => {
if (!interaction.isChatInputCommand()) return;
if (interaction.commandName === 'setup') {
if (!interaction.member.permissions.has(PermissionFlagsBits.ManageGuild)) {
return interaction.reply({ content: `❌Sorry You Need \`ManageGuild\` Permission !`, ephemeral: true })
}
if (!interaction.guild.members.me.permissions.has(PermissionFlagsBits.EmbedLinks)) {
return interaction.reply({ content: `❌Sorry I Need \`EmbedLinks\`Permission !`, ephemeral: true })
}
const em = new EmbedBuilder()
.setAuthor({ name: "Shift Managment" })
.setColor(interaction.member.displayHexColor)
.setDescription(`**•To start shift press on Start shift button below
•To end shift press on End shift button below **`)
.setTimestamp()
const row = new ActionRowBuilder()
.addComponents([
new ButtonBuilder()
.setCustomId('Start shift')
.setLabel(`Start Shift`)
.setStyle(ButtonStyle.Success)
.setEmoji(client.emotes.Startshift)
])
.addComponents([
new ButtonBuilder()
.setCustomId('End shift')
.setLabel(`End Shift`)
.setStyle(ButtonStyle.Danger)
.setEmoji(client.emotes.Endshift)
])
await interaction.channel.send({ embeds: [em], components: [row.toJSON()] })
await interaction.reply({ content: `✅ Succesfully Setup the embed!`, ephemeral: true })
}
}
}
client.on('interactionCreate', async interaction => {
if (interaction.customId === 'Start shift') {
if (!interaction.isButton()) return;
/////////// code
first of all
why do you have 2 listeners
second of all, you cut off the relevant part
i prefer use 2
this is my logic code so it's not important
the problem is in the buttons in embed
No, it‘s not. The problem is in your ////////code
If the buttons still exist that would still be called after a restart
const guild = interaction.guild;
const member = guild.members.cache.get(interaction.user.id);
const roleIdToAdd = '1175872028855783597';
const roleToAdd = guild.roles.cache.get(roleIdToAdd);
const roleIdTorv = '1175876307712745582';
const roleTorv = guild.roles.cache.get(roleIdTorv);
const existingEntry = await TakdemModel.findOne({ userId: interaction.user.id });
if (existingEntry) {
await TakdemModel.findOneAndUpdate({ userId: interaction.user.id }, {
StartedShift: true,
EndedShift: false,
});
} else {
try {
await TakdemModel.create({
interactionId: interaction.id,
userId: interaction.user.id,
name: interaction.user.username,
StartedShift: true,
EndedShift: false,
});
await member.roles.add(roleToAdd);
await member.roles.remove(roleTorv);
} catch (error) {
console.error('Error Line 168:', error);
return;
}
}
const em = new EmbedBuilder()
.setAuthor({ name: "Before you start" })
.setTitle("Before you start your shift you must complete the following tasks :")
.setColor(interaction.member.displayHexColor)
.setDescription(`**First:** You must test your Internet speed using the button below.`)
.addFields(
{ name: 'Second:', value: 'You must test your microphone using the button below.' },
{ name: 'Note:', value: ' You have 3 minutes to provide us with the screenshots to each test in #media! ' },
)
.setThumbnail(client.user.displayAvatarURL({ dynamic: true, size: 2048 }))
const row = new ActionRowBuilder()
.addComponents([
new ButtonBuilder()
.setLabel(`Test your internet speed`)
.setStyle(ButtonStyle.Link)
.setURL("https://www.speedtest.net/")
.setEmoji(client.emotes.internetspeed)
])
.addComponents([
new ButtonBuilder()
.setLabel(`Test your microphone`)
.setStyle(ButtonStyle.Link)
.setURL("https://www.onlinemictest.com/")
.setEmoji(client.emotes.microphonetest)
])
await interaction.reply({ embeds: [em], components: [row.toJSON()] , ephemeral : true })
const logChannelId = '1175875067536744528';
const logChannel = interaction.guild.channels.cache.get(logChannelId);
if (logChannel) {
const shiftStartLogEmbed = new EmbedBuilder()
.setAuthor({ name: interaction.user.username, iconURL: interaction.user.displayAvatarURL({ size: 512, forceStatic: true }) })
.setColor(interaction.member.displayHexColor)
.setTitle('Shift Started')
.setDescription(`${interaction.user} has started their shift.`)
.setThumbnail(interaction.user.displayAvatarURL({ size: 1024, forceStatic: true }))
.setTimestamp();
await logChannel.send({ embeds: [shiftStartLogEmbed] });
}
}
this is the rest of logic when user click on button
how can i solve the problem so ?
have you tried it?
sure
if its not that, it would have errored in the future regardless
the code work perfectly but when i restart the bot
the buttons in embed message didn't work
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
but when i resetup it's work
interaction member gets cached upon receiving the interaction though, so it wouldn’t error
some might do some funly stuff with cache sweepers though
By „not work“ what exactly do you mean? What happens/doesn’t happen?
the bot send this embed by /setup right ?
when i click to the buttons it's work normally but when i restart the bot this button didn't function again
How soon after restart do you try to use them?
10s maybe
According to my experience when i use toJson ( components: [row.toJSON() ) should work
because it save them
How is that related to your issue at hand 
Does your button interaction event listener start unconditionally on bot start? Or is it nested within the command handler?
here
Then there is 0 reason for that not to run after a restart. Add console.logs as stated and find out what happens and what doesn’t
did you see my code ?
According to your experience... what should be the error or why the button didn't fucntion again after restart
Did you read my reply? And no, I never saw your full code, only parts. And in my experience debugging is on you. You got hints on what to do to debug
which is why you need to debug
Can you help me ? or provide some hints ...
👆how often do we have to before you read it and do it?
i try it but nothing in console log and it's very logic . Because the button function normally but when restarting don't function so in conclusion the buttons stop function after restarting and you need to resetup the embed again... the problem still , and i didn't get help
Did you place console.log immediately before the client.on and also first thing in the client.on? Does either of them log to console?
I've tried more than methods (Saving messageID,Embed Info , Buttons ) to DB and them when restart the bot the original message get edited with previous db ... And same Problem
Buttons didn't refunction after restarting the bot
So you still ignore the hints we’ve given you how to properly debug? Guess I‘m done here
i placed console log in all parts of my code (client.on, other).. and nothing shows as error it's show info about because already the code run normally ( do you unerstand my issue?)
The issue is when restarting the bot previous created button didn't function again so no console log and nothing shows because the button didn't function + I've tried more than method to save button data and load after restart and nothing happen the problem still