mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23:30 +01:00
feat(Client): add support for INVITE_CREATE and INVITE_DELETE events (#3720)
* Add support for new Invite events * Merge typings for events Co-Authored-By: Sugden <leoaustin675@gmail.com> * Add warning about requiring permissions * Null check channel and guild * fix: .guilds not .channels
This commit is contained in:
@@ -16,6 +16,8 @@ class ActionsManager {
|
||||
this.register(require('./ChannelUpdate'));
|
||||
this.register(require('./GuildDelete'));
|
||||
this.register(require('./GuildUpdate'));
|
||||
this.register(require('./InviteCreate'));
|
||||
this.register(require('./InviteDelete'));
|
||||
this.register(require('./GuildMemberRemove'));
|
||||
this.register(require('./GuildBanRemove'));
|
||||
this.register(require('./GuildRoleCreate'));
|
||||
|
||||
28
src/client/actions/InviteCreate.js
Normal file
28
src/client/actions/InviteCreate.js
Normal file
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Invite = require('../../structures/Invite');
|
||||
const { Events } = require('../../util/Constants');
|
||||
|
||||
class InviteCreateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const channel = client.channels.get(data.channel_id);
|
||||
const guild = client.guilds.get(data.guild_id);
|
||||
if (!channel && !guild) return false;
|
||||
|
||||
const inviteData = Object.assign(data, { channel, guild });
|
||||
const invite = new Invite(client, inviteData);
|
||||
/**
|
||||
* Emitted when an invite is created.
|
||||
* <info> This event only triggers if the client has `MANAGE_GUILD` permissions for the guild,
|
||||
* or `MANAGE_CHANNEL` permissions for the channel.</info>
|
||||
* @event Client#inviteCreate
|
||||
* @param {Invite} invite The invite that was created
|
||||
*/
|
||||
client.emit(Events.INVITE_CREATE, invite);
|
||||
return { invite };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = InviteCreateAction;
|
||||
29
src/client/actions/InviteDelete.js
Normal file
29
src/client/actions/InviteDelete.js
Normal file
@@ -0,0 +1,29 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Invite = require('../../structures/Invite');
|
||||
const { Events } = require('../../util/Constants');
|
||||
|
||||
class InviteDeleteAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const channel = client.channels.get(data.channel_id);
|
||||
const guild = client.guilds.get(data.guild_id);
|
||||
if (!channel && !guild) return false;
|
||||
|
||||
const inviteData = Object.assign(data, { channel, guild });
|
||||
const invite = new Invite(client, inviteData);
|
||||
|
||||
/**
|
||||
* Emitted when an invite is deleted.
|
||||
* <info> This event only triggers if the client has `MANAGE_GUILD` permissions for the guild,
|
||||
* or `MANAGE_CHANNEL` permissions for the channel.</info>
|
||||
* @event Client#inviteDelete
|
||||
* @param {Invite} invite The invite that was deleted
|
||||
*/
|
||||
client.emit(Events.INVITE_DELETE, invite);
|
||||
return { invite };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = InviteDeleteAction;
|
||||
5
src/client/websocket/handlers/INVITE_CREATE.js
Normal file
5
src/client/websocket/handlers/INVITE_CREATE.js
Normal file
@@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (client, packet) => {
|
||||
client.actions.InviteCreate.handle(packet.d);
|
||||
};
|
||||
5
src/client/websocket/handlers/INVITE_DELETE.js
Normal file
5
src/client/websocket/handlers/INVITE_DELETE.js
Normal file
@@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (client, packet) => {
|
||||
client.actions.InviteDelete.handle(packet.d);
|
||||
};
|
||||
@@ -243,6 +243,8 @@ exports.Events = {
|
||||
GUILD_INTEGRATIONS_UPDATE: 'guildIntegrationsUpdate',
|
||||
GUILD_ROLE_CREATE: 'roleCreate',
|
||||
GUILD_ROLE_DELETE: 'roleDelete',
|
||||
INVITE_CREATE: 'inviteCreate',
|
||||
INVITE_DELETE: 'inviteDelete',
|
||||
GUILD_ROLE_UPDATE: 'roleUpdate',
|
||||
GUILD_EMOJI_CREATE: 'emojiCreate',
|
||||
GUILD_EMOJI_DELETE: 'emojiDelete',
|
||||
@@ -353,6 +355,8 @@ exports.WSEvents = keyMirror([
|
||||
'GUILD_CREATE',
|
||||
'GUILD_DELETE',
|
||||
'GUILD_UPDATE',
|
||||
'INVITE_CREATE',
|
||||
'INVITE_DELETE',
|
||||
'GUILD_MEMBER_ADD',
|
||||
'GUILD_MEMBER_REMOVE',
|
||||
'GUILD_MEMBER_UPDATE',
|
||||
|
||||
1
typings/index.d.ts
vendored
1
typings/index.d.ts
vendored
@@ -188,6 +188,7 @@ declare module 'discord.js' {
|
||||
public on(event: 'guildMemberSpeaking', listener: (member: GuildMember | PartialGuildMember, speaking: Readonly<Speaking>) => void): this;
|
||||
public on(event: 'guildMemberUpdate', listener: (oldMember: GuildMember | PartialGuildMember, newMember: GuildMember | PartialGuildMember) => void): this;
|
||||
public on(event: 'guildUpdate', listener: (oldGuild: Guild, newGuild: Guild) => void): this;
|
||||
public on(event: 'inviteCreate' | 'inviteDelete', listener: (invite: Invite) => void): this;
|
||||
public on(event: 'guildIntegrationsUpdate', listener: (guild: Guild) => void): this;
|
||||
public on(event: 'message' | 'messageDelete' | 'messageReactionRemoveAll', listener: (message: Message | PartialMessage) => void): this;
|
||||
public on(event: 'messageDeleteBulk', listener: (messages: Collection<Snowflake, Message | PartialMessage>) => void): this;
|
||||
|
||||
Reference in New Issue
Block a user