Since yesterday i have with the old code, was working before without any errors and changing code and with the new code, written because of that non solvable problem, the same error.
tried to fix the old code done a new code with the same task, with less code and only one cmd.
/* eslint-disable no-undef */
/* eslint-disable no-empty */
const Discord = require('discord.js');
const Sqlite = require('sqlite3').verbose();
const client = new Discord.Client();
const db = new Sqlite.Database('C:/Users/buett/Documents/Source/Visual Studio Code/Violet Bot/database.db', Sqlite.OPEN_CREATE | Sqlite.OPEN_READWRITE, (err) => {
if (err) {
console.error(err.message);
}
console.log('Database connected!');
});
client.on('error', (err) => {
console.error(err.message);
});
client.once('ready', () => {
console.log(`In ${client.guilds} online!`);
});
client.on('message', async (msg) => {
const prefix = "*";
const args = msg.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
const id = args[0];
const role = args[1];
const emote = args[2]
// const emoji = args[2];
switch (command) {
case 'add':
// eslint-disable-next-line no-case-declarations
if (!msg.author.bot || msg.member.hasPermission("MANAGE_ROLES_OR_PERMISSIONS")) {
let cmd = "*add [ID] [ROLE] [EMOTE]"
if (id > 0) {
if (msg.guild.roles.find(r => r.name == role, r => r.id == role) || msg.mentions.roles.first()) {
const emoteid = emote.replace('>', '').split(':', 3).slice(2);
const emotestring = emoteid[0].toString()
console.log(emoteid)
if (msg.guild.emojis.find(e => e.id == emoteid)) {
await db.run(`CREATE TABLE [IF NOT EXISTS] READD (id INTEGER PRIMARY KEY, role TEXT, emoteid TEXT)`, (error) => {
if (!error) {
db.run(`INSERT INTO READD (id, role, emoteid) VALUES (?, ?, ?)`, [id, role, emotestring])
}
return console.error(error)
});
}
else {
let errorcmd = "EMOTE is not existing or incorrect!"
missingArgsMessage(msg, command, cmd, errorcmd)
}
}
else {
let errorcmd = "ROLE is not existing or incorrect!";
return missingArgsMessage(msg, command, cmd, errorcmd);
}
}
else {
let errorcmd = "ID muss eine Zahl sein!";
missingArgsMessage(msg, command, cmd, errorcmd);
}
}
else {
let perms = "MANAGE_ROLES_OR_PERMISSIONS";
return permsMessage(msg, perms);
}
break;
}
}).login('NDk1MjAzNDMyNzczMTg5NjMy.XUwBdQ.0HdHDSTc_SWsueymgZhLwO7Y3iQ');
function missingArgsMessage(msg, command, cmd, errorcmd) {
msg.channel.send({
embed: {
color: 0xf44336,
title: `**CMD Error:** _${command}_`,
description: `${errorcmd}`,
footer: {
icon_url: 'http://icons.iconarchive.com/icons/froyoshark/enkel/256/iTerm-icon.png',
text: 'CMD Usage >> ' + cmd
}
}
});
}
function permsMessage(msg, perms) {
msg.channel.send({
embed: {
color: 0xd50000,
title: `**PERMS ERROR:** "${perms}"`,
description: `You need more permission to do that!`
}
});
}
I expectet that the code will create a database with the id, role and emote argument but the output is this:
[Error: SQLITE_ERROR: near "READD": syntax error] {
errno: 1,
code: 'SQLITE_ERROR'
}
You need to remove the extra []
in your query, they are here to show that this is optional, so your query becomes
await db.run(`CREATE TABLE IF NOT EXISTS READD (id INTEGER PRIMARY KEY, role TEXT, emoteid TEXT)...`