Here's my code, I have a command handler btw.
const Discord = require('discord.js');
const bot = new Discord.Client();
const token = 'hidden';
const sqlite = require('sqlite3').verbose();
const dayno = '0';
const PREFIX = '$';
const fs = require('fs');
bot.on('message', (message) => {
let userid = message.author.id;
if (message.author.bot || !message.content.startsWith(PREFIX)) return;
if(message.author.bot)return;
let db = new sqlite.Database('./database.db', sqlite.OPEN_READWRITE );
bot.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
const command = require(`./commands/${file}`);
bot.commands.set(command.name, command);
if (message.author.bot || !message.content.startsWith(PREFIX))
return;
let args = message.content.substring(PREFIX.length).split(" ");
switch(args[0]){
case 'help':
bot.commands.get('help').execute(message, args);
break;
case 'getreports':
if(message.member.roles.cache.find(r => r.name
=== "Developers")) return message.channel('You are not authorized to use this command.')
bot.commands.get('getreports').execute(message, args);
break;
case 'getreportsof':
if(message.member.roles.cache.find(r => r.name
=== "Developer")){
bot.commands.get('getreportsof').execute(message, args);
}else{
message.reply('You are not authorized to use this command.')
}
break;
};
};
});
bot.on('ready', () =>{
console.log('Duncan Online');
bot.user.setActivity('$help', {type: "LISTENING"}).catch(console.error);
let db = new sqlite.Database('./database.db', sqlite.OPEN_READWRITE | sqlite.OPEN_CREATE)
db.run('CREATE TABLE IF NOT EXISTS data(userid INTEGER NOT NULL, reports INTEGER NOT NULL)')
});
bot.login(token);
Here's the error :
(node:12456) UnhandledPromiseRejectionWarning: DiscordAPIError: Unknown Message
at RequestHandler.execute (C:\Users\HP_Omen\Desktop\Testing\node_modules\discord.js\src\rest\RequestHandler.js:170:25)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:12456) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a
catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag
`--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:12456) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.