Code Monkey home page Code Monkey logo

Comments (5)

ItzDerock avatar ItzDerock commented on August 17, 2024 1

I'm guessing this will prevent the DiscordAPIError: Unknown Message errors that occur whenever I try to press a button? Because there have been too many event listeners initiated and Discord can't seem to handle them?

Without knowing more info about the stack trace of the Unknown Message errors, can't be 100% sure.

But I have a strong feeling that this will fix this. Unknown Message can come from trying to edit the reply of an interaction after it has expired.

By having the button interaction code in its own file, we are locked to the scope of the button interaction, which has a different expiry than the original interaction, meaning we can't write code that may cause an Unknown Message error to pop up.

from discord-neofetch.

ItzDerock avatar ItzDerock commented on August 17, 2024

Button interaction error: interactions usually fail sometimes. Not good.

This could probably be fixed by moving the button-handling system out of neofetch.js command and into its own event.
Set the customid of the button to be <action>;<user id>. Then you won't need to implement a timeout system on the buttons and reduces memory usage.

Only downside to this is that unfortunately discord doesn't provide a way to delete the original message. You can use buttonInteraction.message.delete(), but that requires the Manage Messages permission on the bot. So a timeout for this or an error message would need to be kept/implemented.

I also looked over the code and saw,

        await action.deferUpdate();
        await action.editReply({
          content: "Here's your neofetch in mobile mode!",
          embeds: [mobileEmbed],
        });

this can be simplified to just a action.update(...) call, which achieves the same thing.

from discord-neofetch.

savioxavier avatar savioxavier commented on August 17, 2024

Thanks a lot of the suggestion @ItzDerock, the discord.js guide/docs didn't have a lot of precise info on how to handle button interactions. I had experienced the errors since I started developing the bot and I had enquired about it to the support server as well, but received no useful information.

I also looked over the code and saw,

	await action.deferUpdate();
	await action.editReply({
    	content: "Here's your neofetch in mobile mode!",
        embeds: [mobileEmbed],
 	});

this can be simplified to just a action.update(...) call, which achieves the same thing.

Right, I guess I can do that!

This could probably be fixed by moving the button-handling system out of neofetch.js command and into its own event.
Set the customid of the button to be ;. Then you won't need to implement a timeout system on the buttons and reduces memory usage.

I'm still confused about this and would need a bit more clarification. Is it possible to discuss about this with you in Discord later, if that's alright?

from discord-neofetch.

ItzDerock avatar ItzDerock commented on August 17, 2024

I'm still confused about this and would need a bit more clarification. Is it possible to discuss about this with you in Discord later, if that's alright?

Currently, looking at the code, every time /neofetch gets ran, 3 collectors are initiated -- which then means 3 more event listeners get added to client#on. Meaning if 5 people were to run the command, 15 additional handlers would be registered to the client, which isn't ideal for memory usage and performance in a larger scale application.

What I propose is that each button handler is moved into its own interactionCreate event registered to handle all buttons from any embed, rather than how it is right now which is an event per button per interaction.

The customId is how the bot will be able to know if the correct user pressed the button.
By setting it to, for example, neofetch;mobile;273629350476382218, in the event, you can split it by ;, and get find that this button is the mobile button for neofetch, and check if interaction.user.id matches the id in the customId.

Then you can use interaction.user for the user data etc and create the mobile version and call .update(...)

This will allow for one event to handle all buttons. And you also won't need to add an expiry/timeout.

If you want to talk more on Discord, I'd be down. What's your name#tag?

from discord-neofetch.

savioxavier avatar savioxavier commented on August 17, 2024

Okay, now that does make a lot of sense, I'll try implementing it locally and see if it works

I'm guessing this will prevent the DiscordAPIError: Unknown Message errors that occur whenever I try to press a button? Because there have been too many event listeners initiated and Discord can't seem to handle them?

If you want to talk more on Discord, I'd be down. What's your name#tag?

It's Skyascii#1860. I may be slow to respond though.

from discord-neofetch.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.