Skip to content

Commit bc7026f

Browse files
author
S222em
committed
fix context menus
1 parent b722d45 commit bc7026f

File tree

2 files changed

+35
-24
lines changed

2 files changed

+35
-24
lines changed

src/managers/GEventHandling.js

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -126,22 +126,12 @@ class GEventHandling {
126126
if (inhibitReturn === false) return;
127127

128128
const cooldown = message.guild ? await this.client.dispatcher.getCooldown(message.guild.id, message.author.id, commandos) : null;
129-
const NSFW = message.guild ? commandos.nsfw && !message.channel.nsfw : null;
130-
const isNotChannelType = type => channelType !== type;
131-
const isNotGuild = guild => !commandos.guildOnly.includes(guild);
132-
133129
const getCooldownMessage = () => this.client.languageFile.COOLDOWN[language].replace(/{COOLDOWN}/g, cooldown.wait).replace(/{CMDNAME}/g, commandos.name);
134-
const getChannelTextOnlyMessage = () => this.client.languageFile.CHANNEL_TEXT_ONLY[language];
135-
const getChannelNewsOnlyMessage = () => this.client.languageFile.CHANNEL_NEWS_ONLY[language];
136-
const getChannelThreadOnlyMessage = () => this.client.languageFile.CHANNEL_THREAD_ONLY[language];
137-
const getNsfwMessage = () => this.client.languageFile.NSFW[language];
138-
const getMissingClientPermissionsMessage = () => this.client.languageFile.MISSING_CLIENT_PERMISSIONS[language].replace('{PERMISSION}', commandos.clientRequiredPermissions.map(v => unescape(v, '_')).join(', '));
139-
const getMissingPermissionsMessage = () => this.client.languageFile.MISSING_PERMISSIONS[language].replace('{PERMISSION}', commandos.userRequiredPermissions.map(v => unescape(v, '_')).join(', '));
140-
const getMissingRolesMessage = () => this.client.languageFile.MISSING_ROLES[language].replace('{ROLES}', `\`${commandos.userRequiredRoles.map(r => message.guild.roles.cache.get(r).name).join(', ')}\``);
141-
const getArgsTimeLimitMessage = () => this.client.languageFile.ARGS_TIME_LIMIT[language];
142130

143131
if (cooldown?.cooldown) return message.reply(getCooldownMessage());
144132

133+
const isNotGuild = guild => !commandos.guildOnly.includes(guild);
134+
145135
if (isNotDm && commandos.guildOnly && isNotGuild(message.guild.id)) return;
146136

147137
if (commandos.userOnly) {
@@ -158,31 +148,47 @@ class GEventHandling {
158148
} else if (message.channel.id !== commandos.channelOnly) { return; }
159149
}
160150

151+
const isNotChannelType = type => channelType !== type;
152+
const getChannelTextOnlyMessage = () => this.client.languageFile.CHANNEL_TEXT_ONLY[language];
153+
const getChannelNewsOnlyMessage = () => this.client.languageFile.CHANNEL_NEWS_ONLY[language];
154+
const getChannelThreadOnlyMessage = () => this.client.languageFile.CHANNEL_THREAD_ONLY[language];
155+
161156
if (isNotDm && commandos.channelTextOnly && isNotChannelType('text')) return message.reply(getChannelTextOnlyMessage());
162157
if (isNotDm && commandos.channelNewsOnly && isNotChannelType('news')) return message.reply(getChannelNewsOnlyMessage());
163158
if (isNotDm && commandos.channelThreadOnly && isNotChannelType('thread')) return message.reply({ content: getChannelThreadOnlyMessage(), ephemeral: true });
164159

160+
const NSFW = message.guild ? commandos.nsfw && !message.channel.nsfw : null;
161+
const getNsfwMessage = () => this.client.languageFile.NSFW[language];
162+
165163
if (NSFW) return message.reply(getNsfwMessage());
166164

165+
const getMissingClientPermissionsMessage = () => this.client.languageFile.MISSING_CLIENT_PERMISSIONS[language].replace('{PERMISSION}', commandos.clientRequiredPermissions.map(v => unescape(v, '_')).join(', '));
166+
167167
if (isNotDm && commandos.clientRequiredPermissions) {
168168
if (!Array.isArray(commandos.clientRequiredPermissions)) commandos.clientRequiredPermissions = [commandos.clientRequiredPermissions];
169169

170170
if (message.channel.permissionsFor(message.guild.me).missing(commandos.clientRequiredPermissions).length > 0) return message.reply(getMissingClientPermissionsMessage());
171171
}
172172

173+
const getMissingPermissionsMessage = () => this.client.languageFile.MISSING_PERMISSIONS[language].replace('{PERMISSION}', commandos.userRequiredPermissions.map(v => unescape(v, '_')).join(', '));
174+
173175
if (isNotDm && commandos.userRequiredPermissions) {
174176
if (!Array.isArray(commandos.userRequiredPermissions)) commandos.userRequiredPermissions = [commandos.userRequiredPermissions];
175177

176178
if (!message.member.permissions.has(commandos.userRequiredPermissions)) return message.reply(getMissingPermissionsMessage());
177179
}
178180

181+
const getMissingRolesMessage = () => this.client.languageFile.MISSING_ROLES[language].replace('{ROLES}', `\`${commandos.userRequiredRoles.map(r => message.guild.roles.cache.get(r).name).join(', ')}\``);
182+
179183
if (isNotDm && commandos.userRequiredRoles) {
180184
if (!Array.isArray(commandos.userRequiredRoles)) commandos.userRequiredRoles = [commandos.userRequiredRoles];
181185

182186
const roles = commandos.userRequiredRoles.some(v => message.member._roles.includes(v));
183187
if (!roles) return message.reply(getMissingRolesMessage());
184188
}
185189

190+
const getArgsTimeLimitMessage = () => this.client.languageFile.ARGS_TIME_LIMIT[language];
191+
186192
let cmdArgs = commandos.args ? JSON.parse(JSON.stringify(commandos.args)) : [];
187193
const objectArgs = [];
188194
const finalArgs = [];
@@ -436,17 +442,7 @@ class GEventHandling {
436442
if (inhibitReturn === false) return;
437443

438444
const cooldown = interaction.guild ? await this.client.dispatcher.getCooldown(interaction.guild.id, interaction.author.id, commandos) : null;
439-
const NSFW = interaction.guild ? commandos.nsfw && !interaction.channel.nsfw : null;
440-
const isNotChannelType = type => channelType !== type;
441-
442445
const getCooldownMessage = () => this.client.languageFile.COOLDOWN[language].replace(/{COOLDOWN}/g, cooldown.wait).replace(/{CMDNAME}/g, commandos.name);
443-
const getChannelTextOnlyMessage = () => this.client.languageFile.CHANNEL_TEXT_ONLY[language];
444-
const getChannelNewsOnlyMessage = () => this.client.languageFile.CHANNEL_NEWS_ONLY[language];
445-
const getChannelThreadOnlyMessage = () => this.client.languageFile.CHANNEL_THREAD_ONLY[language];
446-
const getNsfwMessage = () => this.client.languageFile.NSFW[language];
447-
const getMissingClientPermissionsMessage = () => this.client.languageFile.MISSING_CLIENT_PERMISSIONS[language].replace('{PERMISSION}', commandos.clientRequiredPermissions.map(v => unescape(v, '_')).join(', '));
448-
const getMissingPermissionsMessage = () => this.client.languageFile.MISSING_PERMISSIONS[language].replace('{PERMISSION}', commandos.userRequiredPermissions.map(v => unescape(v, '_')).join(', '));
449-
const getMissingRolesMessage = () => this.client.languageFile.MISSING_ROLES[language].replace('{ROLES}', `\`${commandos.userRequiredRoles.map(r => interaction.guild.roles.cache.get(r).name).join(', ')}\``);
450446

451447
if (cooldown?.cooldown) return interaction.reply.send(getCooldownMessage());
452448

@@ -464,11 +460,22 @@ class GEventHandling {
464460
} else if (interaction.channel.id !== commandos.channelOnly) { return; }
465461
}
466462

463+
const NSFW = interaction.guild ? commandos.nsfw && !interaction.channel.nsfw : null;
464+
const getNsfwMessage = () => this.client.languageFile.NSFW[language];
465+
467466
if (isNotDm && NSFW) { return interaction.reply.send({ content: getNsfwMessage(), ephemeral: true }); }
467+
468+
const isNotChannelType = type => channelType !== type;
469+
const getChannelTextOnlyMessage = () => this.client.languageFile.CHANNEL_TEXT_ONLY[language];
470+
const getChannelNewsOnlyMessage = () => this.client.languageFile.CHANNEL_NEWS_ONLY[language];
471+
const getChannelThreadOnlyMessage = () => this.client.languageFile.CHANNEL_THREAD_ONLY[language];
472+
468473
if (isNotDm && commandos.channelTextOnly && isNotChannelType('text')) { return interaction.reply.send({ content: getChannelTextOnlyMessage(), ephemeral: true }); }
469474
if (isNotDm && commandos.channelNewsOnly && isNotChannelType('news')) { return interaction.reply.send({ content: getChannelNewsOnlyMessage(), ephemeral: true }); }
470475
if (isNotDm && commandos.channelThreadOnly && isNotChannelType('thread')) { return interaction.reply.send({ content: getChannelThreadOnlyMessage(), ephemeral: true }); }
471476

477+
const getMissingClientPermissionsMessage = () => this.client.languageFile.MISSING_CLIENT_PERMISSIONS[language].replace('{PERMISSION}', commandos.clientRequiredPermissions.map(v => unescape(v, '_')).join(', '));
478+
472479
if (isNotDm && commandos.clientRequiredPermissions) {
473480
if (!Array.isArray(commandos.clientRequiredPermissions)) commandos.clientRequiredPermissions = [commandos.clientRequiredPermissions];
474481

@@ -480,6 +487,8 @@ class GEventHandling {
480487
}
481488
}
482489

490+
const getMissingPermissionsMessage = () => this.client.languageFile.MISSING_PERMISSIONS[language].replace('{PERMISSION}', commandos.userRequiredPermissions.map(v => unescape(v, '_')).join(', '));
491+
483492
if (isNotDm && commandos.userRequiredPermissions) {
484493
if (!Array.isArray(commandos.userRequiredPermissions)) commandos.userRequiredPermissions = [commandos.userRequiredPermissions];
485494

@@ -491,6 +500,8 @@ class GEventHandling {
491500
}
492501
}
493502

503+
const getMissingRolesMessage = () => this.client.languageFile.MISSING_ROLES[language].replace('{ROLES}', `\`${commandos.userRequiredRoles.map(r => interaction.guild.roles.cache.get(r).name).join(', ')}\``);
504+
494505
if (isNotDm && commandos.userRequiredRoles) {
495506
if (!Array.isArray(commandos.userRequiredRoles)) commandos.userRequiredRoles = [commandos.userRequiredRoles];
496507

src/structures/ContextMenuInteraction.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class ContextMenuInteraction extends BaseCommandInteraction {
4646

4747
if (options.resolved.users && options.resolved.users[options.target_id]) {
4848
args.push(new User(this.client, options.resolved.users[options.target_id]));
49-
args.push(new GuildMember(this.client, options.resolved.members[options.target_id]));
49+
if (this.guild) args.push(new GuildMember(this.client, options.resolved.members[options.target_id]));
5050
}
5151

5252
if (options.resolved.messages && options.resolved.messages[options.target_id]) {
@@ -66,7 +66,7 @@ class ContextMenuInteraction extends BaseCommandInteraction {
6666

6767
if (options.resolved.users && options.resolved.users[options.target_id]) {
6868
args.user = new User(this.client, options.resolved.users[options.target_id]);
69-
args.member = new GuildMember(this.client, options.resolved.members[options.target_id]);
69+
if (this.guild) args.member = new GuildMember(this.client, options.resolved.members[options.target_id]);
7070
}
7171

7272
if (options.resolved.messages && options.resolved.messages[options.target_id]) {

0 commit comments

Comments
 (0)