UNPKG

dexare

Version:

Modular and extendable Discord bot framework

79 lines (78 loc) 2.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class CommandContext { /** * @param creator The instantiating creator. * @param data The interaction data for the context. * @param respond The response function for the interaction. * @param webserverMode Whether the interaction was from a webserver. */ constructor(cmdsModule, event, args, prefix, message) { this.cmdsModule = cmdsModule; this.client = cmdsModule.client; this.event = event; this.message = message; this.channel = message.channel; this.author = message.author; if (message.member) this.member = message.member; if ('guild' in message.channel) this.guild = message.channel.guild; this.args = args; this.prefix = prefix; } /** Shorthand for `message.channel.createMessage`. */ send(content, file) { return this.client.bot.createMessage(this.channel.id, content, file); } /** Sends a message replying to the original message. */ reply(content, file) { if (typeof content === 'string') content = { content }; content.messageReference = { messageID: this.message.id, channelID: this.channel.id, guildID: this.guild?.id }; return this.client.bot.createMessage(this.channel.id, content, file); } /** * Sends a message with the author's mention prepended to it. * Only prepends in guild channels. */ replyMention(content, file) { if (typeof content === 'string') content = { content }; if (content.content && this.guild) content.content = `${this.message.author.mention}, ${content.content}`; return this.client.bot.createMessage(this.channel.id, content, file); } /** * Fetches the member for this message and assigns it. */ async fetchMember() { if (this.member) return this.member; if (!this.guild) return null; const member = (await this.guild.fetchMembers({ userIDs: [this.author.id] }))[0]; this.guild.members.set(this.author.id, member); this.member = member; return member; } /** * Start typing in the channel the context is in. */ startTyping() { return this.client.startTyping(this.channel.id); } /** * Stop typing in the channel the context is in. */ stopTyping() { return this.client.stopTyping(this.channel.id); } } exports.default = CommandContext;