dev(test) Test only
This commit is contained in:
		| @@ -5,31 +5,6 @@ | ||||
|  | ||||
| ## Interaction | ||||
| <details open> | ||||
| <summary>Fetch Commands data</summary> | ||||
|  | ||||
| ```js | ||||
| /* Save to cache */ | ||||
| // In guild (Opcode 24) | ||||
| const res = await guild.searchInteraction( | ||||
| 	{ | ||||
| 		limit: 100, // default: 1 | ||||
| 		query: 'ping', // optional | ||||
| 		type: 'CHAT_INPUT', // default: 'CHAT_INPUT' | ||||
| 		offset: 0, // default: 0 | ||||
| 		botId: 'botid1' | ||||
| 	} | ||||
| ); | ||||
| // With `type` && `BotId`: Return ApplicationCommand; else return undefined | ||||
| // Fetch all commands (1 bot) Shouldn't be used | ||||
| await bot.applications.fetch( | ||||
| 	{ | ||||
| 		guildId: 'guild id to search', // optional | ||||
| 		force: false, // Using cache or createDMs to bot | ||||
| 	} | ||||
| ); | ||||
| ``` | ||||
| </details> | ||||
| <details open> | ||||
| <summary>Button Click</summary> | ||||
|  | ||||
| ```js | ||||
|   | ||||
| @@ -5,7 +5,7 @@ module.exports = (client, { d: data }) => { | ||||
|   for (const command of data.application_commands) { | ||||
|     const user = client.users.cache.get(command.application_id); | ||||
|     if (!user || !user.bot) continue; | ||||
|     user.applications._add(command, true); | ||||
|     user.application?.commands?._add(command, true); | ||||
|   } | ||||
|   client.emit(Events.GUILD_APPLICATION_COMMANDS_UPDATE, data); | ||||
| }; | ||||
|   | ||||
| @@ -165,6 +165,8 @@ const Messages = { | ||||
|  | ||||
|   INVALID_BOT_METHOD: 'Bot accounts cannot use this method', | ||||
|   INVALID_USER_METHOD: 'User accounts cannot use this method', | ||||
|   BOT_ONLY: 'This method only for bots', | ||||
|   USER_ONLY: 'This method only for users', | ||||
|  | ||||
|   INTERACTION_SEND_FAILURE: msg => `${msg}`, | ||||
|  | ||||
|   | ||||
| @@ -576,12 +576,6 @@ class ApplicationCommand extends Base { | ||||
|    * @param {Message} message Discord Message | ||||
|    * @param {Array<string>} options The options to Slash Command | ||||
|    * @returns {Promise<Snowflake>} Nonce (Discord Timestamp) when command was sent | ||||
|    * @example | ||||
|    * const botID = '12345678987654321' | ||||
|    * const user = await client.users.fetch(botID); | ||||
|    * const application = await user.applications.fetch(); | ||||
|    * const command = application.commands.first(); | ||||
|    * await command.sendSlashCommand(messsage, ['option1', 'option2']); | ||||
|    */ | ||||
|   async sendSlashCommand(message, options = []) { | ||||
|     // Check Options | ||||
| @@ -739,12 +733,6 @@ class ApplicationCommand extends Base { | ||||
|    * @param {Message} message Discord Message | ||||
|    * @param {boolean} sendFromMessage nothing .-. not used | ||||
|    * @returns {Promise<Snowflake>} Nonce (Discord Timestamp) when command was sent | ||||
|    * @example | ||||
|    * const botID = '12345678987654321' | ||||
|    * const user = await client.users.fetch(botID); | ||||
|    * const application = await user.applications.fetch(); | ||||
|    * const command = application.commands.first(); | ||||
|    * await command.sendContextMenu(messsage); | ||||
|    */ | ||||
|   async sendContextMenu(message, sendFromMessage = false) { | ||||
|     if (!sendFromMessage && !(message instanceof Message())) { | ||||
|   | ||||
| @@ -133,8 +133,9 @@ class ClientApplication extends Application { | ||||
|    * @returns {Promise<ClientApplication>} | ||||
|    */ | ||||
|   async fetch() { | ||||
|     if (!this.client.user.bot) throw new Error('INVALID_USER_METHOD'); | ||||
|     const app = await this.client.api.oauth2.applications('@me').get(); | ||||
|     // if (!this.client.user.bot) throw new Error('INVALID_USER_METHOD'); | ||||
|     const app = await this.client.api.oauth2.applications(this.id).get(); | ||||
|     console.log(app); | ||||
|     this._patch(app); | ||||
|     return this; | ||||
|   } | ||||
|   | ||||
| @@ -1100,13 +1100,13 @@ class Message extends Base { | ||||
|       }, | ||||
|     }); | ||||
|     for (const command of data.application_commands) { | ||||
|       user.applications._add(command, true); | ||||
|       user.application?.commands?._add(command, true); | ||||
|     } | ||||
|     contextCMD = user.applications.cache.find(c => c.name == commandName && c.type === 'MESSAGE'); | ||||
|     contextCMD = user.application?.commands?.cache.find(c => c.name == commandName && c.type === 'MESSAGE'); | ||||
|     if (!contextCMD) { | ||||
|       throw new Error( | ||||
|         'INTERACTION_SEND_FAILURE', | ||||
|         `Command ${commandName} is not found (with search)\nList command avalible: ${user.applications.cache | ||||
|         `Command ${commandName} is not found (with search)\nList command avalible: ${user.application?.commands?.cache | ||||
|           .filter(a => a.type == 'MESSAGE') | ||||
|           .map(a => a.name) | ||||
|           .join(', ')}`, | ||||
|   | ||||
| @@ -2,9 +2,9 @@ | ||||
|  | ||||
| const { default: Collection } = require('@discordjs/collection'); | ||||
| const Base = require('./Base'); | ||||
| const ClientApplication = require('./ClientApplication'); | ||||
| const TextBasedChannel = require('./interfaces/TextBasedChannel'); | ||||
| const { Error } = require('../errors'); | ||||
| const ApplicationCommandManager = require('../managers/ApplicationCommandManager'); | ||||
| const { RelationshipTypes } = require('../util/Constants'); | ||||
| const SnowflakeUtil = require('../util/SnowflakeUtil'); | ||||
| const UserFlags = require('../util/UserFlags'); | ||||
| @@ -17,7 +17,6 @@ const UserFlags = require('../util/UserFlags'); | ||||
| class User extends Base { | ||||
|   constructor(client, data) { | ||||
|     super(client); | ||||
|  | ||||
|     /** | ||||
|      * The user's id | ||||
|      * @type {Snowflake} | ||||
| @@ -70,10 +69,10 @@ class User extends Base { | ||||
|     this.mutualGuilds = new Collection(); | ||||
|     /** | ||||
|      * [Bot] Interaction command manager | ||||
|      * @type {?ApplicationCommandManager} | ||||
|      * @type {?ClientApplication} | ||||
|      * @readonly | ||||
|      */ | ||||
|     this.applications = null; | ||||
|     this.application = null; | ||||
|     this._patch(data); | ||||
|   } | ||||
|  | ||||
| @@ -95,7 +94,7 @@ class User extends Base { | ||||
|        */ | ||||
|       this.bot = Boolean(data.bot); | ||||
|       if (this.bot === true) { | ||||
|         this.applications = new ApplicationCommandManager(this.client, undefined, this); | ||||
|         this.application = new ClientApplication(this.client, { id: this.id }); | ||||
|       } | ||||
|     } else if (!this.partial && typeof this.bot !== 'boolean') { | ||||
|       this.bot = false; | ||||
| @@ -488,6 +487,18 @@ class User extends Base { | ||||
|     return data; | ||||
|   } | ||||
|  | ||||
|   async fetchBotInfo() { | ||||
|     if (this.client.user.bot) throw new Error('INVALID_BOT_METHOD'); | ||||
|     if (!this.bot) throw new Error('BOT_ONLY'); | ||||
|     const result = await this.client.api.oauth2.authorize.get({ | ||||
|       query: { | ||||
|         client_id: this.id, | ||||
|         scope: 'bot', | ||||
|       }, | ||||
|     }); | ||||
|     console.log(result); | ||||
|   } | ||||
|  | ||||
|   // These are here only for documentation purposes - they are implemented by TextBasedChannel | ||||
|   /* eslint-disable no-empty-function */ | ||||
|   send() {} | ||||
|   | ||||
| @@ -421,18 +421,18 @@ class TextBasedChannel { | ||||
|     }); | ||||
|     for (const command of data.application_commands) { | ||||
|       if (user.id == command.application_id) { | ||||
|         const c = user.applications._add(command, true); | ||||
|         const c = user.application?.commands?._add(command, true); | ||||
|         if (command.name == commandName) commandTarget = c; | ||||
|       } else { | ||||
|         const tempUser = this.client.users.cache.get(command.application_id); | ||||
|         if (tempUser && tempUser.bot && tempUser.applications) { | ||||
|           tempUser.applications._add(command, true); | ||||
|           tempUser.application?.commands?._add(command, true); | ||||
|         } | ||||
|       } | ||||
|     } | ||||
|     // Remove | ||||
|     commandTarget = | ||||
|       commandTarget || user.applications.cache.find(c => c.name === commandName && c.type === 'CHAT_INPUT'); | ||||
|       commandTarget || user.application?.commands?.cache.find(c => c.name === commandName && c.type === 'CHAT_INPUT'); | ||||
|     if (!commandTarget) { | ||||
|       throw new Error( | ||||
|         'INTERACTION_SEND_FAILURE', | ||||
|   | ||||
		Reference in New Issue
	
	Block a user