Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DiscordAPIError Invalid Form Body when Trying to Purge Messages

So I was pretty sure that this code worked correctly at one point, but recently it was brought to my attention that it sometimes works but not always (read: It will always purge my messages by n amount, but it might not purge another members).

Because I was teaching myself how to use multiple files on this project, the code is actually split between two files. I'm not sure if that has anything to do with the issue or not. Given the size of the two files, I've uploaded them both to pastebin.

The command code. The Function code.

It purges just fine when I try and purge n where n is any number within the acceptable range, but when I try and purge n by username I get an error message stating

DiscordAPIError: Invalid Form Body

limit: Value "" is not int.

(note that is two double quotes, the formatting is a little unclear)

I'm confused as to where it is getting a value that is not an int, as I'm running the amount through praseInt. I've snipped out the code segment that checks if a user is defined and posted it below as I believe it to be the problem:

if (user) { // If User is Provided
  debug.run(`Filtering messages by ${user.username}`);
  const filterBy = user ? user.id : client.user.id;
  messages = messages.filter(m => m.author.id === filterBy).array().slice(0, amount);
}

Any assistance would be greatly appreciated. I'm more or less about to scrap the user feature if I can't figure it out.

Also I apologize for the formatting. I can never get the hang of this sites formatting.

like image 486
Zach Avatar asked Dec 02 '17 04:12

Zach


1 Answers

Try getting rid of .array().slice(0, amount).

The array of fetched messages doesn't need to be cut by the amount variable if the message.channel.fetchMessages({ limit: amount }).then((messages) => { line already limits it.

like image 198
aznguy.mp4 Avatar answered Oct 16 '22 15:10

aznguy.mp4