0
votes

Hey so I'm an amateur JavaScript programmer, and I'm looking to make a "temp mute" command for a bot i am developing. However, i've come across an error i don't know how to solve.

The error is not specifically in my code but after hours of testing i believe ive figured it out: discord.js stores API info such as roles as soon as the command is sent. The problem with that is the tempmute command uses setTimeout() to preform actions after the mute time has expired. One of those actions is checking whether or not the user has been manually un-muted, by checking if the user has the "muted" role. This is where the problem happens. The data stored when the command was sent is different from the real data, an causes the if statement to return false every time, even when it should be returning true.

Here is my question: is there any simple way to cause the data to update and store the real data.

Example:

You start with 3 apples and 0 oranges

That data is stored in the API

when you run the command, that data is stored locally somewhere, for the duration of the command.

the command then takes away your apples, and gives you an orange

it stores how many apples and oranges you had originally for later use

after 5 seconds, the program will start to take that orange away, and give you back your apples

but before it does so, it checks if your orange has already been taken away by someone else, so it asks the API

but the API says you have 3 apples and 0 oranges when you actually have 0 apples and 1 orange

So you don't get your apples back

Would there be any way to make the program update it's data and realize that you have 1 orange?

1

1 Answers

0
votes

To update the latest data from the API, await <Manager>.fetch(). In this case you want to await <Member>.fetch() then access it's roles property. (Note this needs to be in an async function.)