I am working on a Discord bot
that needs to update
someone's nickname, and then reset it back to normal after 2 hours.
I have the code all set up and working when the timeout is set to a few seconds, but when I push the timeout to 2 hours I get a failed request
to the discord server. I'm thinking this is because that channel doesn't stay connected that long -- not sure.
Here is the error:
UnhandledPromiseRejectionWarning: FetchError: request to https://discord.com/api/v7/guilds/297251675616444416/members/711322838556213319 failed, reason: getaddrinfo ENOTFOUND discord.com
at RequestHandler.execute (C:\Users\japhy\projects\enhanced\node_modules\discord.js\src\rest\RequestHandler.js:93:15)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async RequestHandler.push (C:\Users\japhy\projects\enhanced\node_modules\discord.js\src\rest\RequestHandler.js:39:14)
at async GuildMember.edit (C:\Users\japhy\projects\enhanced\node_modules\discord.js\src\structures\GuildMember.js:312:5)
Here is the code itself:
function nicknameTimeout(memberID, memberGuildID) {
guildVar = client.guilds.cache.get(memberGuildID);
member = guildVar.members.cache.get(memberID);
setTimeout(() => {
guildVar = client.guilds.cache.get(memberGuildID);
member = guildVar.members.cache.get(memberID);
nickname = member.nickname;
if (typeof nickname === "object") {
nickname = member.user.username;
}
if (nickname.endsWith("UPDATED***")) {
nickname = nickname.slice(0, -11);
member.setNickname(nickname, "");
}
}, 7200000);
}
Any ideas on how to forcibly reconnect to the client after the timeout, or any other workaround would be much appreciated.