I'm coding a bot that auto-enters a voice chat at midnight, and then plays a song.
I've tried using this:
// require the discord.js module
const Discord = require('discord.js');
// create a new Discord client
const { prefix, token } = require('./config.json');
const client = new Discord.Client();
const fs = require('fs');
const broadcast = client.voice.createBroadcast();
// Checks the date
var date = new Date()
// when the client is ready, run this code
// this event will only trigger one time after logging in
client.once('ready', () => {
console.log('Ready!');
});
client.login(token);
function timeReached(){
setInterval(function(){ date = new Date(); }, 30000);
if (date.getHours() === 14 && date.getMinutes() === 8)
{
return true;
}
else
{
return false;
}
}
client.on("ready", () => {
const channel = client.channels.cache.get("my chat");
if (!channel) return console.error("The channel does not exist!");
while (timeReached != true)
{
timeReached();
}
const conection = channel.connect();
const dispatcher = connection.play ("audio.mp3");
setTimeout(function(){
connection.disconnect();
}, 5000)
});
But after a while running, this message appears on the console:
<--- Last few GCs --->
[13860:00000136C7E96090] 23337 ms: Scavenge 2028.1 (2035.6) -> 2027.6 (2036.4) MB, 9.1 / 0.0 ms (average mu = 0.142, current mu = 0.062) allocation failure
[13860:00000136C7E96090] 23346 ms: Scavenge 2028.8 (2036.4) -> 2028.3 (2047.1) MB, 6.6 / 0.0 ms (average mu = 0.142, current mu = 0.062) allocation failure
[13860:00000136C7E96090] 23485 ms: Scavenge 2035.3 (2047.1) -> 2034.5 (2040.1) MB, 10.3 / 0.0 ms (average mu = 0.142, current mu = 0.062) allocation failure
<--- JS stacktrace --->
==== JS stack trace =========================================
0: ExitFrame [pc: 00007FF7E62C77DD]
Security context: 0x0261bc4408d1 <JSObject>
1: incRefCount(aka incRefCount) [0000021BF3E94141] [internal/timers.js:~289] [pc=0000019AF4857628](this=0x0042117804b1 <undefined>)
2: /* anonymous */ [0000025542A3FFC9] [C:\Users\R2\Desktop\oleo_de_macaco_bot\index.js:~34] [pc=0000019AF485910C](this=0x03aac97c2429 <EventEmitter map = 00000101FF0CA349>)
3: emit [000003FAB26E3969] [events.js:327...
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 00007FF7E56B470F napi_wrap+113583
2: 00007FF7E565F7D6 v8::base::CPU::has_sse+66646
3: 00007FF7E56605D6 v8::base::CPU::has_sse+70230
4: 00007FF7E5E742EE v8::Isolate::ReportExternalAllocationLimitReached+94
5: 00007FF7E5E5C3C1 v8::SharedArrayBuffer::Externalize+833
6: 00007FF7E5D2890C v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1436
7: 00007FF7E5D33B40 v8::internal::Heap::ProtectUnprotectedMemoryChunks+1312
8: 00007FF7E5D30664 v8::internal::Heap::PageFlagsAreConsistent+3204
9: 00007FF7E5D25E63 v8::internal::Heap::CollectGarbage+1283
10: 00007FF7E5D2C6F4 v8::internal::Heap::GlobalSizeOfObjects+212
11: 00007FF7E5D6251B v8::internal::StackGuard::HandleInterrupts+907
12: 00007FF7E5AAD719 v8::internal::interpreter::JumpTableTargetOffsets::iterator::operator=+7737
13: 00007FF7E62C77DD v8::internal::SetupIsolateDelegate::SetupHeap+546637
14: 0000019AF4857628
Judging by this line:
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
It seems to be that my bot is running out of memory. How can I alocate more memory to it or circuvent this problem?
P.S.: It is my very first bot, and i know very little about javascript.