我是一個不和諧的機器人開發人員,我為我的機器人使用 SQLite 資料庫。我sqlite3通過 npm 命令安裝并使用它,沒有問題,但現在我無法使用它,因為它會修改值。我這里有一些代碼:
const ghostChannels = await new Promise((resolve, reject) =>
client.db.all(`SELECT * FROM "Ghosts"`, (err, rows) =>
err ? reject(err) : resolve(rows)
)
);
ghostChannels.forEach(async (channel) => {
const guildchannel = await message.member.guild.channels.cache.get(
channel.id
);
console.log(channel.id);
console.log(guildchannel);
const mess = await guildchannel.send(message.member);
await mess.delete();
});
不幸的是,它回傳一個錯誤:
Uncaught TypeError TypeError: channel.send is not a function

所以我查看了id, 發現它與資料庫中的 ID 不同:

我不知道如何解決它,所以如果有人知道,請告訴我:)
uj5u.com熱心網友回復:
問題是您嘗試將雪花存盤為整數(例如988185997772738610),而您應該將它們存盤為字串("988185997772738610")。由于這些 ID 大于 53 位 ( MAX_SAFE_INTEGER),JavaScript 難以解釋它們。它只能安全??地表示 -(2 53 - 1) 和 2 53 - 1 之間的整數。
| 最大安全整數 | 9007199254740992 |
| 你的整數 | 988185997772738610 |
| 你的整數變成 | 988185997772738600 |
如您所見,0如果將它們存盤為整數,則每個不和諧 ID/雪花的最后兩位數字都會變為。您甚至可以在下面嘗試:
console.log(988185997772738610)
// => 988185997772738600
console.log('988185997772738610')
// => "988185997772738610"
因此,要解決您的問題,請確保將頻道(和其他)ID 作為字串插入資料庫。
uj5u.com熱心網友回復:
也許你做錯了?在任何需要的時候呼叫database一些gateway(idk確切的名字)。例如:
const ghostChannels = await new Promise((resolve, reject) =>
client.db.all(`SELECT * FROM "Ghosts"`, (err, rows) =>
err ? reject(err) : resolve(rows)
)
);
ghostChannels.forEach(async (channel) => {
const guildchannel = await message.member.guild.channels.cache.get(
channel.id
);
console.log(channel.id);
console.log(guildchannel);
const mess = await channel.send(message.member);
await mess.delete();
});
因為你打電話guildchannel給db
你:
const mess = await channel.send(message.member);
應該:
const mess = await guildchannel.send(message.member);
編輯:
我已經看到guildchannel顯示為undefined,您可以嘗試:
await guildchannel.channel?.send
或類似的東西:
const chan = message.guild.channels.cache.get(`${channel.id}`)
chan.send("set")
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/497184.html
標籤:javascript 节点.js sqlite 不和谐.js 节点-sqlite3
上一篇:SQLiteClosureTabe:如何改進我的SQL以拆分樹
下一篇:資料庫內容未在生產中顯示
