I'm trying to write a Discord bot that contains several features. The main ones that are relevant to this question is a command that adds a number to a array, and one that removes a number from an array provided it exists. While I've already gotten a working "AddNumber" command completed, my main issue is in the "RemoveNumber" code. I'm using the arr.indexOf
function to determine if it exists inside the array currently. However, whenever I attempt the function I get the error: UnhandledPromiseRejectionWarning: TypeError: arr.indexOf is not a function
. While I have found several solutions online, and attempted most of them, none of them helped. How can I fix this? Alternatively, is there another way to check?
Relevant Code (More can be provided if needed!):
// Main File (Where the array is made, passed to needed files using async)
const arr = [
"1",
];
// End main file
// Command File
if(arr.indexOf(gametoend) === -1){
message.reply('that game doesn\'t exist! Did you put in the wrong number?');
} else {
message.channel.send('Placeholder success');
}
// End command file
Update: This is the full error text that pops up. For the question I changed the array name from inprogressgames to arr, but that isn't the case here, hence the different name. Image link
Update 2: Put the code in a pastebin, hopefully it helps. Link