node.js - db.run 不是函数:Discord.js sqlite
问题描述
所以我收到这个错误,特别是“(node:9780) UnhandledPromiseRejectionWarning: TypeError: db.run is not a function”我不知道出了什么问题,所以我想这里有人可以帮我解决这个问题。
const Discord = require("discord.js");
const client = new Discord.Client();
const bot = new Discord.Client();
const sql = require("sqlite")
const db = sql.open('./database.sqlite', { Promise });
const fs = require("fs");
const staff = ["97122523086340096", "450241616331145217", "283438590875402240", "288755621787074560"]
const config = require("./config.json");
client.on("ready", async () => {
console.log(`${client.user.username} is ready to help servers!`)
console.log ("Warning: I am being locally hosted. During high usage times, the bot may crash.")
db.run("CREATE TABLE IF NOT EXISTS guild (guildId TEXT, language INTEGER, links INTEGER)");
console.log(`I am available in 1 shard! I am in ${client.guilds.size} guilds and serving ${bot.users.size}`)
client.user.setActivity("For sat!help", {type: "WATCHING"}, {status:"dnd"});
client.user.setPresence( {status:"idle"} )
});
fs.readdir("./events/", (err, files) => {
if (err) return console.error(err);
files.forEach(file => {
let eventFunction = require(`./events/${file}`);
let eventName = file.split(".")[0];
client.on(eventName, (...args) => eventFunction.run(client, ...args));
});
});
client.on("message", message => {
if (message.author.bot) return;
if(message.content.indexOf(config.prefix) !== 0) return;
const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
try {
let commandFile = require(`./commands/${command}.js`);
commandFile.run(bot, message, args);
} catch (err) {
return
}
});
client.on("guildCreate", guild => {
let guildp = guild.owner
guildp.send("Thanks for adding me to your server! \n To save you some time I would suggest you run the command 'sat!setup' to create the nessecary roles and channels for the bot. \n Please note that the channel is not made with perms.\n ***[PLEASE NOTE!] - I am still in beta so any issues with any part of the bot please tell us with sat!bug! \n Thanks!")
})
client.login(config.token);
解决方案
兑现承诺
从 NPM - https://www.npmjs.com/package/sqlite:
const dbPromise = sqlite.open('./database.sqlite', { Promise });
const db = await dbPromise;
推荐阅读
- r - 在 R 中创建匹配对
- android - Android Studio 显示错误。但构建成功并且工作正常
- node.js - 如何清除我的时间间隔并停止重复的 API 调用?
- ios - Flutter:iOS - 新的 IAP 功能不适用于旧产品
- javascript - 如何根据左侧元素的单击更改基于右侧窗格的名称?
- c - 将二维数组作为参数传递
- javascript - 存储经过身份验证的登录名的好方法是什么?
- python - 如何从多处理池中返回多个值作为数据框?
- javascript - 将 prop 值从父组件传递给子组件,并根据父 prop 值映射子组件
- javascript - JSON.parse 与所有双引号