查询 better-sqlite3 记录数据

Query better-sqlite3 for record data

所以我的数据库中有一个名为 logging 的 table,其架构为 guildid & channel

如果 guildid 匹配,我需要获取 channel 的内容,我 运行 console.log(logs) 看看实际发生了什么,它说 { channel: '495602952778678274' }

我选择留下完整的代码,这样您就可以清楚地看到我要完成的工作。

client.on('messageDelete', async (message) => {
  const logs = sql.prepare(`SELECT channel FROM logging WHERE guildid = ${message.guild.id};`).get();
  console.log(logs);
  if (!logs) return;
  const entry = await message.guild.fetchAuditLogs({
    type: 'MESSAGE_DELETE'
  }).then(audit => audit.entries.first());
  let user = "";
  if (entry.extra.channel.id === message.channel.id &&
    (entry.target.id === message.author.id) &&
    (entry.createdTimestamp > (Date.now() - 5000)) &&
    (entry.extra.count >= 1)) {
    user = entry.executor.username;
  } else {
    user = message.author.username;
  }
  client.channels.get(logs).send(`A message was deleted in ${message.channel.name} by ${user}`);
});

我也试过 logs.send... 最后我试了

const id = sql.prepare(`SELECT channel FROM logging WHERE guildid = ${message.guild.id};`).get();
const logs = client.channels.get(id);
client.channels.get(logs).send('Send a message');

如果你做了 console.log(logs) 并且得到了 { channel: '495602952778678274' } 那么你应该这样做:

const result = sql.prepare(`SELECT channel FROM logging WHERE guildid = ${message.guild.id};`).get();
const logs = client.channels.get(result.channel);
logs.send('Send a message');