問題描述
每當機器人啟動時,它就會開始向控制台發送垃圾郵件,沒有明顯的問題 (Whenever the bot starts up, it just starts spamming the console with no visible issue)
由於某種原因,當我啟動我的機器人時,它只是開始向控制台日誌發送垃圾郵件。我已經設置好了,所以當我的機器人在線時,它會在控制台中打印一條消息,所以我知道它在線。但是,它只是無緣無故地以奇怪的間隔一遍又一遍地發送垃圾郵件。
這是我啟動時的代碼:
client.on("ready", () => {
console.log(`${client.user.username} is now online!`)
client.user.setActivity("over the server", {
type: "WATCHING"
});
});
所以它只是沒有任何作用對我來說,為什麼它會開始向我的控制台日誌發送垃圾郵件。這是一個常見問題嗎?在某種情況下會發生嗎?請告訴我,謝謝。
參考解法
方法 1:
I tried your code and it doesn't do anything particular in the console.
I think your issue come form your internet connection : if the bot keeps deconnecting and reconnecting due to your Internet, the client.on("ready", () => {
will be executed multiple times.
if you still want to keep the console.log, you can try to fix it manually with an if statement :</p>
var firstTimeConnecting = 1
client.on("ready", () => {
if (firstTimeConnecting = 1){
console.log(`${client.user.username} is now online!`)
firstTimeConnecting = 0
}
client.user.setActivity("over the server", {
type: "WATCHING"
});
});