mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
feat: add UserContextMenuInteraction and MessageContextMenuInteraction (#7003)
Co-authored-by: Rodry <38259440+ImRodry@users.noreply.github.com> Co-authored-by: Suneet Tipirneni <77477100+suneettipirneni@users.noreply.github.com> Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com> Co-authored-by: GrapeColor <grapecolor@users.noreply.github.com>
This commit is contained in:
@@ -4,8 +4,9 @@ const Action = require('./Action');
|
||||
const AutocompleteInteraction = require('../../structures/AutocompleteInteraction');
|
||||
const ButtonInteraction = require('../../structures/ButtonInteraction');
|
||||
const CommandInteraction = require('../../structures/CommandInteraction');
|
||||
const ContextMenuInteraction = require('../../structures/ContextMenuInteraction');
|
||||
const MessageContextMenuInteraction = require('../../structures/MessageContextMenuInteraction');
|
||||
const SelectMenuInteraction = require('../../structures/SelectMenuInteraction');
|
||||
const UserContextMenuInteraction = require('../../structures/UserContextMenuInteraction');
|
||||
const { Events, InteractionTypes, MessageComponentTypes, ApplicationCommandTypes } = require('../../util/Constants');
|
||||
|
||||
let deprecationEmitted = false;
|
||||
@@ -25,8 +26,10 @@ class InteractionCreateAction extends Action {
|
||||
InteractionType = CommandInteraction;
|
||||
break;
|
||||
case ApplicationCommandTypes.USER:
|
||||
InteractionType = UserContextMenuInteraction;
|
||||
break;
|
||||
case ApplicationCommandTypes.MESSAGE:
|
||||
InteractionType = ContextMenuInteraction;
|
||||
InteractionType = MessageContextMenuInteraction;
|
||||
break;
|
||||
default:
|
||||
client.emit(
|
||||
|
||||
@@ -113,6 +113,7 @@ exports.MessageAttachment = require('./structures/MessageAttachment');
|
||||
exports.MessageButton = require('./structures/MessageButton');
|
||||
exports.MessageCollector = require('./structures/MessageCollector');
|
||||
exports.MessageComponentInteraction = require('./structures/MessageComponentInteraction');
|
||||
exports.MessageContextMenuInteraction = require('./structures/MessageContextMenuInteraction');
|
||||
exports.MessageEmbed = require('./structures/MessageEmbed');
|
||||
exports.MessageMentions = require('./structures/MessageMentions');
|
||||
exports.MessagePayload = require('./structures/MessagePayload');
|
||||
@@ -140,6 +141,7 @@ exports.ThreadChannel = require('./structures/ThreadChannel');
|
||||
exports.ThreadMember = require('./structures/ThreadMember');
|
||||
exports.Typing = require('./structures/Typing');
|
||||
exports.User = require('./structures/User');
|
||||
exports.UserContextMenuInteraction = require('./structures/UserContextMenuInteraction');
|
||||
exports.VoiceChannel = require('./structures/VoiceChannel');
|
||||
exports.VoiceRegion = require('./structures/VoiceRegion');
|
||||
exports.VoiceState = require('./structures/VoiceState');
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const Base = require('./Base');
|
||||
const { InteractionTypes, MessageComponentTypes } = require('../util/Constants');
|
||||
const { InteractionTypes, MessageComponentTypes, ApplicationCommandTypes } = require('../util/Constants');
|
||||
const Permissions = require('../util/Permissions');
|
||||
const SnowflakeUtil = require('../util/SnowflakeUtil');
|
||||
|
||||
@@ -160,6 +160,22 @@ class Interaction extends Base {
|
||||
return InteractionTypes[this.type] === InteractionTypes.APPLICATION_COMMAND && typeof this.targetId !== 'undefined';
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether this interaction is a {@link UserContextMenuInteraction}
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isUserContextMenu() {
|
||||
return this.isContextMenu() && ApplicationCommandTypes[this.targetType] === ApplicationCommandTypes.USER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether this interaction is a {@link MessageContextMenuInteraction}
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isMessageContextMenu() {
|
||||
return this.isContextMenu() && ApplicationCommandTypes[this.targetType] === ApplicationCommandTypes.MESSAGE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether this interaction is an {@link AutocompleteInteraction}
|
||||
* @returns {boolean}
|
||||
|
||||
20
src/structures/MessageContextMenuInteraction.js
Normal file
20
src/structures/MessageContextMenuInteraction.js
Normal file
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
const ContextMenuInteraction = require('./ContextMenuInteraction');
|
||||
|
||||
/**
|
||||
* Represents a message context menu interaction.
|
||||
* @extends {ContextMenuInteraction}
|
||||
*/
|
||||
class MessageContextMenuInteraction extends ContextMenuInteraction {
|
||||
/**
|
||||
* The message this interaction was sent from
|
||||
* @type {Message|APIMessage}
|
||||
* @readonly
|
||||
*/
|
||||
get targetMessage() {
|
||||
return this.options.getMessage('message');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MessageContextMenuInteraction;
|
||||
29
src/structures/UserContextMenuInteraction.js
Normal file
29
src/structures/UserContextMenuInteraction.js
Normal file
@@ -0,0 +1,29 @@
|
||||
'use strict';
|
||||
|
||||
const ContextMenuInteraction = require('./ContextMenuInteraction');
|
||||
|
||||
/**
|
||||
* Represents a user context menu interaction.
|
||||
* @extends {ContextMenuInteraction}
|
||||
*/
|
||||
class UserContextMenuInteraction extends ContextMenuInteraction {
|
||||
/**
|
||||
* The user this interaction was sent from
|
||||
* @type {User}
|
||||
* @readonly
|
||||
*/
|
||||
get targetUser() {
|
||||
return this.options.getUser('user');
|
||||
}
|
||||
|
||||
/**
|
||||
* The member this interaction was sent from
|
||||
* @type {?(GuildMember|APIGuildMember)}
|
||||
* @readonly
|
||||
*/
|
||||
get targetMember() {
|
||||
return this.options.getMember('user');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = UserContextMenuInteraction;
|
||||
17
typings/index.d.ts
vendored
17
typings/index.d.ts
vendored
@@ -1227,6 +1227,8 @@ export class Interaction<Cached extends CacheType = CacheType> extends Base {
|
||||
public isCommand(): this is CommandInteraction<Cached>;
|
||||
public isAutocomplete(): this is AutocompleteInteraction<Cached>;
|
||||
public isContextMenu(): this is ContextMenuInteraction<Cached>;
|
||||
public isUserContextMenu(): this is UserContextMenuInteraction<Cached>;
|
||||
public isMessageContextMenu(): this is MessageContextMenuInteraction<Cached>;
|
||||
public isMessageComponent(): this is MessageComponentInteraction<Cached>;
|
||||
public isSelectMenu(): this is SelectMenuInteraction<Cached>;
|
||||
}
|
||||
@@ -1536,6 +1538,13 @@ export class MessageComponentInteraction<Cached extends CacheType = CacheType> e
|
||||
public static resolveType(type: MessageComponentTypeResolvable): MessageComponentType;
|
||||
}
|
||||
|
||||
export class MessageContextMenuInteraction<Cached extends CacheType = CacheType> extends ContextMenuInteraction<Cached> {
|
||||
public readonly targetMessage: CacheTypeReducer<Cached, Message, APIMessage>;
|
||||
public inGuild(): this is MessageContextMenuInteraction<'present'>;
|
||||
public inCachedGuild(): this is MessageContextMenuInteraction<'cached'>;
|
||||
public inRawGuild(): this is MessageContextMenuInteraction<'raw'>;
|
||||
}
|
||||
|
||||
export class MessageEmbed {
|
||||
private _fieldEquals(field: EmbedField, other: EmbedField): boolean;
|
||||
|
||||
@@ -2188,6 +2197,14 @@ export class User extends PartialTextBasedChannel(Base) {
|
||||
public toString(): UserMention;
|
||||
}
|
||||
|
||||
export class UserContextMenuInteraction<Cached extends CacheType = CacheType> extends ContextMenuInteraction<Cached> {
|
||||
public readonly targetUser: User;
|
||||
public readonly targetMember: CacheTypeReducer<Cached, GuildMember, APIInteractionGuildMember>;
|
||||
public inGuild(): this is UserContextMenuInteraction<'present'>;
|
||||
public inCachedGuild(): this is UserContextMenuInteraction<'cached'>;
|
||||
public inRawGuild(): this is UserContextMenuInteraction<'raw'>;
|
||||
}
|
||||
|
||||
export class UserFlags extends BitField<UserFlagsString> {
|
||||
public static FLAGS: Record<UserFlagsString, number>;
|
||||
public static resolve(bit?: BitFieldResolvable<UserFlagsString, number>): number;
|
||||
|
||||
Reference in New Issue
Block a user