Skip to content

Commit

Permalink
Merge pull request #23 from versx/fix-delete
Browse files Browse the repository at this point in the history
Update to Discord.js v13 and fixes
  • Loading branch information
versx authored Nov 23, 2022
2 parents 3408784 + 2c9bdc7 commit 9dfc4cb
Show file tree
Hide file tree
Showing 10 changed files with 1,590 additions and 2,529 deletions.
3,835 changes: 1,412 additions & 2,423 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,26 @@
},
"homepage": "https://github.com/versx/EventWatcher#readme",
"dependencies": {
"@discordjs/rest": "^1.0.1",
"axios": "^0.21.1",
"discord.js": "^12.5.1",
"discord-api-types": "^0.37.0",
"discord.js": "^13.9.2",
"eslint": "^7.16.0",
"i18n": "^0.9.0",
"lodash": "^4.17.21",
"mustache": "^4.1.0"
},
"devDependencies": {
"@types/axios": "^0.14.0",
"@types/i18n": "^0.12.0",
"@types/lodash": "^4.14.182",
"@types/mustache": "^4.1.1",
"@types/node": "^14.0.1",
"@typescript-eslint/eslint-plugin": "^3.0.0",
"@typescript-eslint/parser": "^3.0.0",
"eslint": "^7.0.0",
"typescript": "^3.9.7",
"nodemon": "^2.0.7"
"nodemon": "^2.0.7",
"typescript": "^3.9.10"
},
"nodemonConfig": {
"ignore": [
Expand Down
14 changes: 7 additions & 7 deletions src/handlers/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ export const commands = new Collection<string, Command>();
* Parse and validate Discord commands handler
* @param {*} message
*/
export const handleCommand = async (message: Message) => {
export const handleCommand = async (message: Message<boolean>): Promise<void> => {
// Skip bot messages and messages that don't start with our prefix
if (!message.content.startsWith(config.prefix) || message.author.bot)
return;

// Skip messages not in our allowed bot command channels unless it's a DM
if (!config.botChannelIds.includes(message.channel.id) && message.channel.type !== 'dm')
if (!config.botChannelIds.includes(message.channel.id) && message.channel.type !== 'DM')
return;

// Trim prefix and split remaining by space to get our args provided, and command (if any)
Expand All @@ -38,11 +38,11 @@ export const handleCommand = async (message: Message) => {

// Check if owner only command
if (command.ownerOnly && !config.adminIds.includes(message.author.id))
return message.reply({ embed: { description: ':x: **Access Not Granted** You do not have permission to execute this command.', color: 0xff1100 }});
message.reply({ embeds: [{ description: ':x: **Access Not Granted** You do not have permission to execute this command.', color: 0xff1100 }] });

// Check if guild only command that does not support DMs
if (command.guildOnly && message.channel.type === 'dm') {
return message.reply({ embed: { description: 'Command does not support DM messages!', color: 0xff1100} });
if (command.guildOnly && message.channel.type === 'DM') {
message.reply({ embeds: [{ description: 'Command does not support DM messages!', color: 0xff1100}] });
}

// Check if command needs arguments set and if they aren't set
Expand All @@ -51,13 +51,13 @@ export const handleCommand = async (message: Message) => {
if (command.usage) {
reply += `\nThe proper usage would be: \`${config.prefix}${command.name} ${command.usage}\``;
}
return message.channel.send({ embed: { description: reply, color: 0xff1100} });
message.channel.send({ embeds: [{ description: reply, color: 0xff1100}] });
}

try {
await command.execute(message, args);
} catch (error) {
console.error(error);
message.reply({ embed: { description: 'There was an error trying to execute that command!', color: 0xff1100} });
message.reply({ embeds: [{ description: 'There was an error trying to execute that command!', color: 0xff1100}] });
}
}
8 changes: 4 additions & 4 deletions src/handlers/dm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { User } from 'discord.js';
* @param {*} data
*/
export const sendDm = async (member: User, data: any): Promise<void> => {
if (!member || !data) {
console.warn('Member or data is null, cannot send direct message');
if (!member) {
console.error('Failed to find Discord member', member);
return;
}
if (!member) {
console.error('Failed to find member', member);
if (!data) {
console.warn('DM data is null, cannot send direct message');
return;
}
const dm = await member.createDM();
Expand Down
Loading

0 comments on commit 9dfc4cb

Please sign in to comment.