-1
const Discord = require("discord.js");
const client = new Discord.Client();
const ayarlar = require("./ayalar.json");
let takipedilen = "648424230081265664";
let onlinetakipedilen = 648424230081265664;
let hesap = "648424230081265664";

client.on("ready", () => {
    console.log(`Logged in as ${client.user.tag}!`);
});

client.on("presenceUpdate", (oldMember, newMember) => {
    if (!oldMember.id == onlinetakipedilen) return;
    if (oldMember.id == onlinetakipedilen) {
        if (oldMember.presence.status != newMember.presence.status) {
            var interval = setInterval(function () {
                // use the message's channel (TextChannel) to send a new message
                client.guilds
                    .get("812505935280472084")
                    .channels.get("812506306321580062")
                    .send("**" + `${newMember.user.username}` + "**" + " " + "şuanda" + " " + `${newMember.presence.status}`)
                    .catch(console.error); // add error handling here
            }, 1000);
        }
    }
});

This my code and it's spamming the same thing to my text channel. This is the result; Result

Jakye
  • 6,440
  • 3
  • 19
  • 38
Ulus
  • 1

2 Answers2

0

You're doing the first evaluation kind of wrong.

Instead of doing this:

if(!oldMember.id == onlinetakipedilen) return;

try:

if(oldMember.id !== onlinetakipedilen) return;
E. Mancebo
  • 629
  • 3
  • 10
  • I tried this parameter but its still spamming. – Ulus Feb 22 '21 at 20:13
  • by the way, where's `onlinetakipedilen` set? – E. Mancebo Feb 22 '21 at 20:15
  • At top, there is the code; const Discord = require('discord.js'); const client = new Discord.Client(); const ayarlar = require('./ayalar.json'); let takipedilen = "648424230081265664"; let onlinetakipedilen = 648424230081265664; let hesap = "648424230081265664"; client.on('ready', () => { console.log(`Logged in as ${client.user.tag}!`); }); – Ulus Feb 22 '21 at 20:16
0

The issue is because onlinetakipedilen is an Integer, not a String.

Replace 5th line with:

let onlinetakipedilen = "648424230081265664";

If you are wondering why this is happening please read What is JavaScript's highest integer value that a number can go to without losing precision?.


You're also comparing a Boolean to an Integer.

if (oldMember.id !== onlinetakipedilen)

Equality comparisons and sameness

Jakye
  • 6,440
  • 3
  • 19
  • 38