查询Better-sqlite3以获取记录数据

时间:2019-01-14 01:25:23

标签: node.js discord.js better-sqlite3

因此,我的数据库中有一个名为logging的表,其架构为guildid & channel

如果channel匹配,我需要获取guildid的内容,我运行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');

1 个答案:

答案 0 :(得分:0)

If you did console.log(logs) and it gave { channel: '495602952778678274' } then you should do:

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');