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,
|
Permissions,
|
||||||
Message,
|
Message,
|
||||||
MessageEmbed,
|
MessageEmbed,
|
||||||
Guild,
|
|
||||||
CommandInteraction,
|
CommandInteraction,
|
||||||
GuildMember,
|
GuildMember,
|
||||||
|
ReplyMessageOptions,
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
import { CommandBuilder, PermissionCheckTypes } from "./types.js";
|
import { CommandBuilder, PermissionCheckTypes } from "./types.js";
|
||||||
import { PermissionsError } from "./errors.js";
|
import { PermissionsError } from "./errors.js";
|
||||||
@@ -26,7 +26,12 @@ export class Command {
|
|||||||
private function: (
|
private function: (
|
||||||
interaction?: Message | CommandInteraction,
|
interaction?: Message | CommandInteraction,
|
||||||
cmdParams?: InputParameter[]
|
cmdParams?: InputParameter[]
|
||||||
) => void | string | MessageEmbed | Promise<void | string | MessageEmbed>;
|
) =>
|
||||||
|
| void
|
||||||
|
| string
|
||||||
|
| MessageEmbed
|
||||||
|
| ReplyMessageOptions
|
||||||
|
| Promise<void | string | MessageEmbed | ReplyMessageOptions>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Command constructor
|
* Command constructor
|
||||||
@@ -93,7 +98,15 @@ export class Command {
|
|||||||
: memberPermissions.any(this.permissions, true))
|
: memberPermissions.any(this.permissions, true))
|
||||||
) {
|
) {
|
||||||
const fnResult = await this.function(interaction, cmdParams);
|
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);
|
await interaction?.reply(fnResult);
|
||||||
} else if (fnResult instanceof MessageEmbed) {
|
} else if (fnResult instanceof MessageEmbed) {
|
||||||
await interaction?.channel.send({ embeds: [fnResult] });
|
await interaction?.channel.send({ embeds: [fnResult] });
|
||||||
@@ -126,7 +139,21 @@ export class Command {
|
|||||||
cmdParams
|
cmdParams
|
||||||
);
|
);
|
||||||
try {
|
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
|
interaction.replied
|
||||||
? await interaction.editReply({
|
? await interaction.editReply({
|
||||||
content: fnResult,
|
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 { InputParameter, ParameterSchema } from "./Parameter.js";
|
||||||
import { PermissionResolvable, Message, MessageEmbed } from "discord.js";
|
import { PermissionResolvable, Message, MessageEmbed } from "discord.js";
|
||||||
import type { Command } from "./Command.js";
|
import type { Command } from "./Command.js";
|
||||||
@@ -27,7 +32,12 @@ export interface CommandBuilder {
|
|||||||
function: (
|
function: (
|
||||||
interaction?: Message | CommandInteraction,
|
interaction?: Message | CommandInteraction,
|
||||||
cmdParams?: InputParameter[]
|
cmdParams?: InputParameter[]
|
||||||
) => void | string | MessageEmbed | Promise<void | string | MessageEmbed>;
|
) =>
|
||||||
|
| void
|
||||||
|
| string
|
||||||
|
| MessageEmbed
|
||||||
|
| ReplyMessageOptions
|
||||||
|
| Promise<void | string | MessageEmbed | ReplyMessageOptions>;
|
||||||
}
|
}
|
||||||
export interface PhraseOccurrenceData {
|
export interface PhraseOccurrenceData {
|
||||||
command: Command;
|
command: Command;
|
||||||
|
|||||||
Reference in new issue
Block a user