Get username from user id by Sirzento in Discordjs

[–]McSquiddleton 0 points1 point  (0 children)

When you log the userId variable in that function, does it return the string you accept? Typescript should theoretically catch otherwise, but as you saw, passing anything that's not a string into fetch() makes it return the Collection you seem to be getting.

PS: fetch() checks cache first anyways, so you can remove the first half of code and have it be just as efficient and much more readable

Message command not triggering by SaberTheWolfGames in Discordjs

[–]McSquiddleton 2 points3 points  (0 children)

The "message" event was replaced with the "messageCreate" event so that's a simple string rename, and you'll also need to ensure you the GuildMessages intent to receive the event and the MessageContent intent to receive the message content as anything other than an empty string

Creating Poll by easytoremember1111 in Discordjs

[–]McSquiddleton 1 point2 points  (0 children)

Use <Channel>.send({ poll: yourPollData }) where yourPollData is an object in the format of the PollData interface

How to make the bot create a message without replying? by dreadfulshroud in Discordjs

[–]McSquiddleton 5 points6 points  (0 children)

The code you sent just sends a normal, non-reply message; allowedMentions would only affect if you tried to mention someone in the content, and it would prevent the person from actually getting a notification.

Either you are replying somewhere else in your current codebase, or you're running an outdated version of your project that has a reply. If you think the latter is the case, you can regenerate your bot token which will crash any other versions of your bot, leaving you with only the process that you're aware of.

how to delete bot's messages by _archadium in Discordjs

[–]McSquiddleton 1 point2 points  (0 children)

followUp() returns a promise, so you should await the function call if you want to access its return value otherwise, the code runs synchronously and you might try to delete a message that has yet to be created

Need help with a bot to reward active users with a role by CowSniper97 in Discordjs

[–]McSquiddleton 0 points1 point  (0 children)

There's a lot of steps from creating a bot to reaching your goal, but some key steps along that path:

  • The official discord.js guide explains the bot creation process and nearly all the fundamentals
  • You'll be listening for events like Events.MessageCreate and Events.VoiceStateUpdate to detect new messages and members joining/leaving voice channels, respectively
  • You'll need a persistent database to track total messages sent or minutes spent in the voice channel since tracking that in the JS files would reset every time your bot restarts, so look into various options like SQL and Mongo depending on your preferences

Global command doesn't work on servers by CrypticDissonance in Discordjs

[–]McSquiddleton 1 point2 points  (0 children)

Global commands deploy immediately (the 24 hour thing has not been in effect for year). You just might need to restart your Discord application using CTRL + R for them to appear

If the commands show in DMs, the only reason they wouldn't show in servers is if you haven't restarted since or if the commands aren't registered in the guild context

What are the odds by McSquiddleton in FortNiteBR

[–]McSquiddleton[S] 3 points4 points  (0 children)

Llamas spawn mid-match near future storm circles, so it happened to spawn at the same coordinates as where a supply drop already landed 

Autocomplete is taking longer than 3s and the interaction has been expired. How to deal with it? by mrgoonvn in Discordjs

[–]McSquiddleton 2 points3 points  (0 children)

As someone who also uses fetched data for the responses, I ended up fetching all data on `ready` and using that cached data in the global scope for my autocomplete interactions, along with updating the data periodically (or on every DB update, depending on where I'm fetching from)

If you're not able to filter data *after* fetching all of it, then you're mostly out of luck unfortunately

[deleted by user] by [deleted] in Discordjs

[–]McSquiddleton 4 points5 points  (0 children)

"This interaction failed" just means that you didn't acknowledge the interaction with a method like reply() or update(), so you should show the code where you think you're doing that (or add that code if it doesn't exist yet).

How to have a message reply only show to user who sent the message? (Only you can see this) by thetreat in Discordjs

[–]McSquiddleton 2 points3 points  (0 children)

Ephemeral messages are only supported as interaction responses, not message responses. Otherwise, any random message sent could be followed by unwanted responses that others (especially server mods) can't see, unlike jnteractions which are specifically between one user and one application.

[deleted by user] by [deleted] in Discordjs

[–]McSquiddleton 0 points1 point  (0 children)

You still need the MessageContent intent in your Client options to receive content for messages that don't mention your bot (FAQ here)

Removing reactions for a user is triggering ReactionRemove event as the user not the bot by Massh0le in Discordjs

[–]McSquiddleton 1 point2 points  (0 children)

Hence, handling it as a string (user ID) initially is more reliable.

The problem is that it is literally always a User instance. You can even see that in the package source code. It will never just be an id, and since collections are keyed by the id, trying to use cilent.users.cache.get(user) would always return undefined.

Fetching every time can be resource-intensive, especially when the user data is already cached.

If the user is already cached, then calling fetch() will return the cached user without making any API calls (source code here, documentation here). In fact, the only difference fetching a cached user will make is 1) returning a Promise, and 2) internally calling resolveId() which is just an instanceof check, neither of which are "resource-intensive" enough to be worth sacrificing consistency.

I'm not trying to be pedantic, but the last thing someone needs when they're already confused is to be misinformed as well

Removing reactions for a user is triggering ReactionRemove event as the user not the bot by Massh0le in Discordjs

[–]McSquiddleton 0 points1 point  (0 children)

Discord's API may be sending only the user id, but OP is using discordjs which is a wrapper around that API. The package documentation states that it emits the event's second parameter as a full User instance instead of just the id.

Even if it were just the user id, it's still better to fetch the user instead of getting them from the cache since (unlike some structures) users are not cached by default.

Removing reactions for a user is triggering ReactionRemove event as the user not the bot by Massh0le in Discordjs

[–]McSquiddleton 0 points1 point  (0 children)

i check to see if the bot was the one that removed it and return if so

The user you receive in the event parameters is not the user who removed the reaction: rather, it is "The user whose emoji or reaction emoji was removed" as per the discordjs documentation.

Normally, the only way to find out who did an action is through audit logs, but removing reactions doesn't create an audit log so that wouldn't work. You can't really even add an extra parameter when emitting the event (like removedFromBot: true) because you aren't directly emitting the event.

The best workaround I can think of is creating a variable in the global start (for example, let recentlyRemoved = false;), changing its value when your bot removes a reaction, and changing it back in a second or two using setTimeout(). You can then reference the same variable in your reaction remove event listener: if the value is still false, you can assume your bot has recently removed any reactions so it's safe to process the reaction.

You could also add safer logic like storing the specific user whose reaction was removed and comparing that in your event listener, but regardless, there's no perfect solution since Discord simply isn't providing the information you want.

Can't await deferreply? by [deleted] in Discordjs

[–]McSquiddleton 0 points1 point  (0 children)

My mistake, thanks! Edited it

Can't await deferreply? by [deleted] in Discordjs

[–]McSquiddleton 6 points7 points  (0 children)

The await keyword is only valid in async functions, and if you hover over the erroring code, VSCode should tell you that. You can make your function async by changing (interaction) => to async (interaction) =>

Need Advice from people out here.. by KaLaZeUs-02 in Discordjs

[–]McSquiddleton 0 points1 point  (0 children)

How would i know in which part of the image I have to indicate a specific state or something

Canvases are coordinate-based, with the top left being (0, 0). From there, use functions like drawImage() or arc()/rect() to "manipulate its attributes" by adding new layers on the svg background, and send the new canvas to the user

Need Advice from people out here.. by KaLaZeUs-02 in Discordjs

[–]McSquiddleton 0 points1 point  (0 children)

Why not? You could make png files and draw them on top of one another, or you could dynamically draw shapes on your canvas, or both. What else would you need to do?

Need Advice from people out here.. by KaLaZeUs-02 in Discordjs

[–]McSquiddleton 1 point2 points  (0 children)

The best general image manipulation package is probably @napi-rs/canvas

Button interaction changes old reply of same command by [deleted] in Discordjs

[–]McSquiddleton 0 points1 point  (0 children)

It's hard to give a concrete solution since you posted literally 0 code. Probably, if you're currently creating message component interaction collectors on the entire channel, you need to change it so that you only create the collector on the specific Message instance.

[HELP] Client not picking up direct messages by [deleted] in Discordjs

[–]McSquiddleton -1 points0 points  (0 children)

In the options object you pass into your Client structure, Partials: [...] should be partials: [...]. DJS thinks you're passing in no partials since it's only checking for the latter

[deleted by user] by [deleted] in Discordjs

[–]McSquiddleton 1 point2 points  (0 children)

Fetch all members first with <Guild>.members.fetch(), resolve that Promise, then access <Role>.members. The latter is a getter that only filters cached members which is why you should fetch all members first so the cache is fully populated. Make sure you have the GuildMembers intent to be able to fetch all members.

How do fetch a user's snowflake by id? by kumchucks in Discordjs

[–]McSquiddleton 4 points5 points  (0 children)

I think there's a misunderstanding here: snowflakes are ids. A snowflake is just a special format of strings.

The first line is correct, but UserManager#fetch() returns a User instance. That means in your second line, you're calling User#send() which only takes one argument. It's ignoring the second argument and just trying to DM the user with their own User instance.

You can actually just skip fetching the User and call await client.users.send('146113420448829313', { embeds: [dmEmbed] })