Archived
added ReplyMessageOptions to commands as a return value
This commit is contained in:
1 parent
5baa44e7fc
commit
d37015a617
2 files changed
+43
-6
No files matched your search
+31
-4
@@ -3,9 +3,9 @@ import {
|
||||
Permissions,
|
||||
Message,
|
||||
MessageEmbed,
|
||||
Guild,
|
||||
CommandInteraction,
|
||||
GuildMember,
|
||||
ReplyMessageOptions,
|
||||
} from "discord.js";
|
||||
import { CommandBuilder, PermissionCheckTypes } from "./types.js";
|
||||
import { PermissionsError } from "./errors.js";
|
||||
@@ -26,7 +26,12 @@ export class Command {
|
||||
private function: (
|
||||
interaction?: Message | CommandInteraction,
|
||||
cmdParams?: InputParameter[]
|
||||
) => void | string | MessageEmbed | Promise<void | string | MessageEmbed>;
|
||||
) =>
|
||||
| void
|
||||
| string
|
||||
| MessageEmbed
|
||||
| ReplyMessageOptions
|
||||
| Promise<void | string | MessageEmbed | ReplyMessageOptions>;
|
||||
|
||||
/**
|
||||
* Command constructor
|
||||
@@ -93,7 +98,15 @@ export class Command {
|
||||
: memberPermissions.any(this.permissions, true))
|
||||
) {
|
||||
const fnResult = await this.function(interaction, cmdParams);
|
||||
if (typeof fnResult == "string") {
|
||||
if (
|
||||
"content" in (fnResult as ReplyMessageOptions) ||
|
||||
"embeds" in (fnResult as ReplyMessageOptions) ||
|
||||
"files" in (fnResult as ReplyMessageOptions) ||
|
||||
"components" in (fnResult as ReplyMessageOptions) ||
|
||||
"sticker" in (fnResult as ReplyMessageOptions)
|
||||
) {
|
||||
await interaction.reply(fnResult as ReplyMessageOptions);
|
||||
} else if (typeof fnResult == "string") {
|
||||
await interaction?.reply(fnResult);
|
||||
} else if (fnResult instanceof MessageEmbed) {
|
||||
await interaction?.channel.send({ embeds: [fnResult] });
|
||||
@@ -126,7 +139,21 @@ export class Command {
|
||||
cmdParams
|
||||
);
|
||||
try {
|
||||
if (typeof fnResult == "string") {
|
||||
if (
|
||||
"content" in (fnResult as ReplyMessageOptions) ||
|
||||
"embeds" in (fnResult as ReplyMessageOptions) ||
|
||||
"files" in (fnResult as ReplyMessageOptions) ||
|
||||
"components" in (fnResult as ReplyMessageOptions) ||
|
||||
"sticker" in (fnResult as ReplyMessageOptions)
|
||||
) {
|
||||
interaction.replied
|
||||
? await interaction.editReply(
|
||||
fnResult as ReplyMessageOptions
|
||||
)
|
||||
: await interaction.reply(
|
||||
fnResult as ReplyMessageOptions
|
||||
);
|
||||
} else if (typeof fnResult == "string") {
|
||||
interaction.replied
|
||||
? await interaction.editReply({
|
||||
content: fnResult,
|
||||
|
||||
+12
-2
@@ -1,4 +1,9 @@
|
||||
import { ClientOptions, ColorResolvable, CommandInteraction } from "discord.js";
|
||||
import {
|
||||
ClientOptions,
|
||||
ColorResolvable,
|
||||
CommandInteraction,
|
||||
ReplyMessageOptions,
|
||||
} from "discord.js";
|
||||
import { InputParameter, ParameterSchema } from "./Parameter.js";
|
||||
import { PermissionResolvable, Message, MessageEmbed } from "discord.js";
|
||||
import type { Command } from "./Command.js";
|
||||
@@ -27,7 +32,12 @@ export interface CommandBuilder {
|
||||
function: (
|
||||
interaction?: Message | CommandInteraction,
|
||||
cmdParams?: InputParameter[]
|
||||
) => void | string | MessageEmbed | Promise<void | string | MessageEmbed>;
|
||||
) =>
|
||||
| void
|
||||
| string
|
||||
| MessageEmbed
|
||||
| ReplyMessageOptions
|
||||
| Promise<void | string | MessageEmbed | ReplyMessageOptions>;
|
||||
}
|
||||
export interface PhraseOccurrenceData {
|
||||
command: Command;
|
||||
|
||||
Reference in new issue
Block a user