You're attempting to access the Trash variable, but it doesn't contain what you think it does. Trash is being assigned the Promise that represents the end result of the function chain.
You should take the result being passed into then() and use that as a parameter to your bulkDelete() call.
Client.on("message", async function(message) {
if(message.channel.id != "506258018032418817") return;
setInterval (function () {
message.channel.fetchMessages({ limit: 100 }).then(
function(deleteThese) { message.channel.bulkDelete(deleteThese); })
}, 900000);
});
Keep in mind, the logic for this function is not sound. The pseudo-code goes like this:
- whenever a message is sent to this specific channel
- queue up a timer to happen in 15 minutes
- after 15 minutes, delete 100 messages from the channel
Consider what happens if this happens
1:00 Paul talks in channel
--- (timer 1 is started)
1:01 Elizabeth responds
--- (timer 2 is started)
... < time passes > ...
1:14 Charles says something in the channel
... < timer 1 triggers; room is wiped > ...
1:15 Diane says something in response to Charles' deleted message
... < timer 2 triggers; room is wiped > ...
1:16 Charles asks Diane to repeat what she just said
You might want to change your approach to pass a time in your fetchMessages() call so it only deletes messages that are 15 minutes old or older.
asyncif you are not usingawait? You also are missing a.before thethen()so I'm not sure how this is working. Any console errors? - aug