0

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.

Toasty
  • 1,850
  • 1
  • 6
  • 21
Japhy
  • 45
  • 7
  • You could try doing a cronjob instead of `setInterval`. More info could be found [here (relating to scheduling messages ex)](https://stackoverflow.com/a/49079053/15073477) or by doing a good search. – PerplexingParadox Apr 18 '21 at 21:14
  • Thank you for your reply, but I can't do a cronjob because of the same issue. I tried to run the same code using a cronjob, but it was no different from the timeout because the client timed out the same way. I've tried creating a second client, but I can't create another with the same token, and I only have one token. Any other ideas? – Japhy Apr 19 '21 at 20:03
  • I was looking at your error, and it seems like from [here](https://anidiots.guide/common-errors#error-getaddrinfo-enotfound-gateway-discord-gg-gateway-discord-gg-443) that it was only an internet issue, not the code. – PerplexingParadox Apr 23 '21 at 14:19

0 Answers0