#After restarting Buttons dosen't work

57 messages · Page 1 of 1 (latest)

atomic prairieBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • 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!
marble solar
#

??

pliant parrot
#

By using the interactionCreate event rather than collectors

marble solar
#

to see how to use it

marble basinBOT
marble solar
pliant parrot
#

yes

marble solar
#

i'am already using this

#

and the button didn't work after restating

pliant parrot
#

Show your code then

marble solar
# pliant parrot 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 
pliant parrot
#

first of all

#

why do you have 2 listeners

#

second of all, you cut off the relevant part

marble solar
marble solar
#

the problem is in the buttons in embed

viral lantern
#

No, it‘s not. The problem is in your ////////code

#

If the buttons still exist that would still be called after a restart

marble solar
# viral lantern No, it‘s not. The problem is in your ////////code
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

pliant parrot
#

Not all members are cached

#

And <Interaction>.member exists

marble solar
pliant parrot
#

have you tried it?

marble solar
#

sure

pliant parrot
#

if its not that, it would have errored in the future regardless

marble solar
#

the code work perfectly but when i restart the bot
the buttons in embed message didn't work

marble basinBOT
#

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
marble solar
#

but when i resetup it's work

viral lantern
pliant parrot
#

some might do some funly stuff with cache sweepers though

viral lantern
marble solar
viral lantern
#

How soon after restart do you try to use them?

marble solar
#

10s maybe

#

According to my experience when i use toJson ( components: [row.toJSON() ) should work

#

because it save them

viral lantern
#

How is that related to your issue at hand waitWhat

#

Does your button interaction event listener start unconditionally on bot start? Or is it nested within the command handler?

marble solar
#

unconditionally

#

look at code

viral lantern
marble solar
#

According to your experience... what should be the error or why the button didn't fucntion again after restart

viral lantern
#

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

marble solar
#

i think the problem is in my code

#

but i don't know exactly were

pliant parrot
#

which is why you need to debug

marble solar
viral lantern
marble solar
viral lantern
#

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?

marble solar
viral lantern
#

So you still ignore the hints we’ve given you how to properly debug? Guess I‘m done here

marble solar
# viral lantern So you still ignore the hints we’ve given you how to properly debug? Guess I‘m d...

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