Skip to content

Commit

Permalink
Fix bug where bot couldn't read from DMs
Browse files Browse the repository at this point in the history
  • Loading branch information
earthernsence committed Aug 6, 2021
1 parent 53d53ff commit 65ffb72
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const fs = require("fs");
const config = require("./config.json");
const functions = require("./functions");

const client = new Discord.Client({ intents: [Discord.Intents.FLAGS.GUILDS, Discord.Intents.FLAGS.GUILD_MESSAGES] });
const client = new Discord.Client({ intents: [Discord.Intents.FLAGS.GUILDS, Discord.Intents.FLAGS.GUILD_MESSAGES, Discord.Intents.FLAGS.DIRECT_MESSAGES], partials: ["MESSAGE", "CHANNEL", "USER"] });
const commandFiles = fs.readdirSync("./commands").filter(file => file.endsWith(".js"));
client.commands = new Discord.Collection();

Expand Down
14 changes: 10 additions & 4 deletions classes/Command.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,19 @@ class Command {

doMissingArgCatch(message, args) {
if (message.content.length > 1000) {
message.channel.send(`You cannot try to trigger a command over this length!`);
this.send(message, `You cannot try to trigger a command over this length!`);
return;
}
if (args[0] === undefined) {
message.channel.send(functions.getMessage("missingArg", { name: this.name, acceptableArgs: this.acceptableArgs }), { split: true });
this.send(message, functions.getMessage("missingArg", { name: this.name, acceptableArgs: this.acceptableArgs }));
}
}

send(message, sent) {
if (message.channel.type === "dm") message.author.send(sent, { split: true });
else message.channel.send(sent, { split: true });
}

/**
* Does the regular command execution. Made to reduce clutter in the main execute() method.
* @param {Object} message Object that contains all the information about the message.
Expand All @@ -91,9 +96,10 @@ class Command {
message.channel.send(`You cannot try to trigger a command over this length!`);
return;
}
const sent = this.getArgMessage(args[0].toLowerCase());
if (args[0] === undefined) this.doMissingArgCatch(message, args);
else if (this.getCheck(id, message) && this.acceptableArgs.includes(args[0].toLowerCase())) message.channel.send(this.getArgMessage(args[0].toLowerCase()), { split: true });
else if (!(args[0] === undefined)) message.channel.send(functions.getMessage("error", { args, name: this.name, acceptableArgs: this.acceptableArgs }), { split: true });
else if (this.getCheck(id, message) && this.acceptableArgs.includes(args[0].toLowerCase())) this.send(message, sent);
else if (!(args[0] === undefined)) this.send(message, functions.getMessage("error", { args, name: this.name, acceptableArgs: this.acceptableArgs }));
else message.channel.send(functions.getMessage("shouldNeverAppear"), { split: true });
}
}
Expand Down
2 changes: 1 addition & 1 deletion commands/news.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
const { NewsCommand } = require("../classes/NewsCommand");

const newsMessageObject = {
"listmobile": "<https://paste.ee/p/LGLeE>",
"listmobile": "<https://gist.github.com/earthernsence/2661619a3e4ca8089709f9fe19395f77>",
"listweb": "<https://github.com/IvarK/IvarK.github.io/blob/master/javascripts/core/newsticker.js>"
};

Expand Down
Binary file modified database.sqlite
Binary file not shown.
2 changes: 1 addition & 1 deletion functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function endgameCheck(id, message) {
function botCommandsCheck(id, message) {
// 603002159864348703 is #bots in Earth's things
// 722268615973273725 is #general in bot test server
return config.ids.botCommands.includes(id) || id === "603002159864348703" || id === "722268615973273725" || message.channel.type === "dm";
return config.ids.botCommands.includes(id) || id === "603002159864348703" || id === "722268615973273725" || message.channel.type === "DM";
}

/**
Expand Down

0 comments on commit 65ffb72

Please sign in to comment.