mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 09:33:32 +01:00
refactor: only cache commands from own user (#6161)
This commit is contained in:
@@ -3,18 +3,13 @@
|
||||
const { Events } = require('../../../util/Constants');
|
||||
|
||||
module.exports = (client, { d: data }) => {
|
||||
let command;
|
||||
const commandManager = data.guild_id ? client.guilds.cache.get(data.guild_id)?.commands : client.application.commands;
|
||||
if (!commandManager) return;
|
||||
|
||||
if (data.guild_id) {
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
if (!guild) return;
|
||||
command = guild.commands._add(data);
|
||||
} else {
|
||||
command = client.application.commands._add(data);
|
||||
}
|
||||
const command = commandManager._add(data, data.application_id === client.application.id);
|
||||
|
||||
/**
|
||||
* Emitted when an application command is created.
|
||||
* Emitted when a guild application command is created.
|
||||
* @event Client#applicationCommandCreate
|
||||
* @param {ApplicationCommand} command The command which was created
|
||||
*/
|
||||
|
||||
@@ -3,20 +3,15 @@
|
||||
const { Events } = require('../../../util/Constants');
|
||||
|
||||
module.exports = (client, { d: data }) => {
|
||||
let command;
|
||||
const commandManager = data.guild_id ? client.guilds.cache.get(data.guild_id)?.commands : client.application.commands;
|
||||
if (!commandManager) return;
|
||||
|
||||
if (data.guild_id) {
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
if (!guild) return;
|
||||
command = guild.commands._add(data);
|
||||
guild.commands.cache.delete(data.id);
|
||||
} else {
|
||||
command = client.application.commands._add(data);
|
||||
client.application.commands.cache.delete(data.id);
|
||||
}
|
||||
const isOwn = data.application_id === client.application.id;
|
||||
const command = commandManager._add(data, isOwn);
|
||||
if (isOwn) commandManager.cache.delete(data.id);
|
||||
|
||||
/**
|
||||
* Emitted when an application command is deleted.
|
||||
* Emitted when a guild application command is deleted.
|
||||
* @event Client#applicationCommandDelete
|
||||
* @param {ApplicationCommand} command The command which was deleted
|
||||
*/
|
||||
|
||||
@@ -3,21 +3,14 @@
|
||||
const { Events } = require('../../../util/Constants');
|
||||
|
||||
module.exports = (client, { d: data }) => {
|
||||
let oldCommand;
|
||||
let newCommand;
|
||||
const commandManager = data.guild_id ? client.guilds.cache.get(data.guild_id)?.commands : client.application.commands;
|
||||
if (!commandManager) return;
|
||||
|
||||
if (data.guild_id) {
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
if (!guild) return;
|
||||
oldCommand = guild.commands.cache.get(data.id)?._clone() ?? null;
|
||||
newCommand = guild.commands._add(data);
|
||||
} else {
|
||||
oldCommand = client.application.commands.cache.get(data.id)?._clone() ?? null;
|
||||
newCommand = client.application.commands._add(data);
|
||||
}
|
||||
const oldCommand = commandManager.cache.get(data.id)?._clone() ?? null;
|
||||
const newCommand = commandManager._add(data, data.application_id === client.application.id);
|
||||
|
||||
/**
|
||||
* Emitted when an application command is updated.
|
||||
* Emitted when a guild application command is updated.
|
||||
* @event Client#applicationCommandUpdate
|
||||
* @param {?ApplicationCommand} oldCommand The command before the update
|
||||
* @param {ApplicationCommand} newCommand The command after the update
|
||||
|
||||
Reference in New Issue
Block a user