我正在創建一個小的不和諧機器人。當設定在客戶端啟動后啟動的命令時,其中之一,即 setTimeout,什么都不做。這是代碼的一部分:
client.once('ready', () => {
console.log('the bot is online!');
});
client.on('messageCreate', (message) => {
if (message.content === 'ping') {
message.reply({
content: 'pong',
})
}
setTimeout(client.channels.cache.get('<channel ID>').send('time is out'), 3000);
});
沒有錯誤顯示,只是沒有發生任何事情:(如果您知道出了什么問題,請告訴我
uj5u.com熱心網友回復:
首先,您需要像這樣轉義“超時”字串中的 ' 字符:
'time\'s out'
其次,您必須將回呼作為第一個引數傳遞給 setTimeout,因此您需要像這樣使用箭頭函式。
setTimeout(() => {client.channels.cache.get('<channel ID>').send('time\'s out')}, 3000);
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/421509.html
標籤:
