Sqlite Discord.js:无法读取null的属性“运行” [英] Sqlite Discord.js: Cannot read property 'run' of null

查看:93
本文介绍了Sqlite Discord.js:无法读取null的属性“运行”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我试图为Discord.js机器人建立一个SQLite数据库,但是当我尝试使用SQLite时,却不断出现此错误(无法读取'run'为null的属性)。我所有的朋友似乎都没有这个问题,所以我想来这里。抱歉,这是一个令人讨厌的问题。.我还是这个新手

So I am trying to make a SQLite database for my Discord.js bot, but I keep getting this error (Cannot read property of 'run' of null) when I try to use SQLite. Non of my friends seem to have this problem, so I thought to come here. Sorry if this is like a noobish question.. I'm still a little new to this

这是我的代码:

    const Discord = require("discord.js");
    const client = new Discord.Client();
    const bot = new Discord.Client();
    const sql = require("sqlite")
    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.")
    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"} )
    sql.run("CREATE TABLE IF NOT EXISTS guild (guildId TEXT, language INTEGER, links INTEGER)")
    });
   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);


推荐答案

您需要打开与数据库的连接,然后运行

You need to open connection with the database and then run the SQL query.

const sql = require("sqlite")
const db = sql.open('./database.sqlite', { Promise });

db.run("CREATE TABLE IF NOT EXISTS guild (guildId TEXT, language INTEGER, links INTEGER)");

这篇关于Sqlite Discord.js:无法读取null的属性“运行”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆