Files
discordeno/template/nodejs/Structures/CommandResponse.js
meister03 405e4a7533 Discordeno.js guide (#2313)
* Update Template and Add Discordeno.js notes in favour of depreciating Discord Structures

* Add package.json

* deno fmt

Co-authored-by: meister03 <meisterpi@gmail.com>
Co-authored-by: LTS20050703 <87189679+lts20050703@users.noreply.github.com>
Co-authored-by: LTS20050703 <lts20050703@gmail.com>
2022-08-23 10:31:14 -04:00

51 lines
1.3 KiB
JavaScript

class Responses {
constructor(data) {
this.manager = data.manager;
this.args = this._validateArguments(data.args);
this.replied = false;
}
async reply(content) {
// When just a string is passed, we assume it's the content -> transform to correct formatted payload
if (typeof content === "string") content = { content };
if (this.interaction) {
if (this.replied) return this.followUp(content);
const reply = await this.interaction.reply(content);
this.replied = true;
return {};
}
if (this.message) {
if (this.replied) return this.followUp(content);
const msg = await this.message.channel.send(content);
//Assign properties to the response
const response = this.client.messages.forge(msg);
this.replied = true;
return response;
}
}
async followUp(content) {
if (this.interaction) {
const reply = await this.interaction.followUp(content);
return {};
}
if (this.message) {
const msg = await this.message.channel.send(content);
const response = this.client.messages.forge(msg);
return response;
}
}
onError(error) {
return this.reply({ content: `A unknown Error happend: \n> ${error}` });
}
_validateArguments(args) {
this.args = args;
return args;
}
}
module.exports = Responses;