Hyper
Hyper
SIASapphire - Imagine a framework
Created by Hyper on 2/7/2024 in #sapphire-support
Precondition Command
In a global precondition, is it possible to get the command object for the command the precondition is being run on?
7 replies
SIASapphire - Imagine a framework
Created by Hyper on 1/6/2024 in #sapphire-support
Any reason as to why this event wouldn't be firing?
import { ApplyOptions } from "@sapphire/decorators";
import { Events, Listener, type MessageCommandErrorPayload, UserError } from "@sapphire/framework";
import { EmbedBuilder } from "discord.js";
//import { captureException } from '@sentry/node';
import * as Sentry from "@sentry/node";
import functions from "../../../utils/functions";
import config from "../../../config";

@ApplyOptions<Listener.Options>({
event: Events.MessageCommandError,
})
export class MessageCommandErrorListener extends Listener {
public override async run(error: UserError, { message }: MessageCommandErrorPayload) {
console.log("hi")
if (!error.name) return await functions.error(message, error.toString());
if (error.toString().includes("No subcommand was matched with the provided arguments."))
return await functions.error(message, "Invalid subcommand.");
if (typeof error === "string") {
await functions.error(message, error);
return;
}

if (typeof error !== "string") {
const sentry = Sentry.captureException(error);

const errorID = await functions.rng(12);
const errorEmbed = new EmbedBuilder();

errorEmbed.setAuthor({
name: `Command Error`,
iconURL: this.container.client.user?.displayAvatarURL(),
});
errorEmbed.setDescription(`${error}`);
errorEmbed.addFields([
{ name: "Error ID", value: `> ${errorID.toString()}`, inline: true },
{
name: "Command",
value: `> ${arguments[1].command!.name || "Unknown"}`,
inline: true,
},
{
name: "Sentry Report",
value: "[Click Here](https://sentry.io/" + sentry + ")",
},
]);

this.container.logger.error(
`Encountered the following error while running ${
arguments[1].command.name
}: ${errorID.toString()} - Sentry report: https://sentry.io/${sentry}`,
);

if (message.channel || message)
await message.channel.send({
content: `Failed to execute this command. Report this error ID (\`${errorID}\`) to a developer.`,
});
await functions.sendWebhook(config.webhooks.errors.id, config.webhooks.errors.token, { embeds: [errorEmbed] });
return;
}
}
}
import { ApplyOptions } from "@sapphire/decorators";
import { Events, Listener, type MessageCommandErrorPayload, UserError } from "@sapphire/framework";
import { EmbedBuilder } from "discord.js";
//import { captureException } from '@sentry/node';
import * as Sentry from "@sentry/node";
import functions from "../../../utils/functions";
import config from "../../../config";

@ApplyOptions<Listener.Options>({
event: Events.MessageCommandError,
})
export class MessageCommandErrorListener extends Listener {
public override async run(error: UserError, { message }: MessageCommandErrorPayload) {
console.log("hi")
if (!error.name) return await functions.error(message, error.toString());
if (error.toString().includes("No subcommand was matched with the provided arguments."))
return await functions.error(message, "Invalid subcommand.");
if (typeof error === "string") {
await functions.error(message, error);
return;
}

if (typeof error !== "string") {
const sentry = Sentry.captureException(error);

const errorID = await functions.rng(12);
const errorEmbed = new EmbedBuilder();

errorEmbed.setAuthor({
name: `Command Error`,
iconURL: this.container.client.user?.displayAvatarURL(),
});
errorEmbed.setDescription(`${error}`);
errorEmbed.addFields([
{ name: "Error ID", value: `> ${errorID.toString()}`, inline: true },
{
name: "Command",
value: `> ${arguments[1].command!.name || "Unknown"}`,
inline: true,
},
{
name: "Sentry Report",
value: "[Click Here](https://sentry.io/" + sentry + ")",
},
]);

this.container.logger.error(
`Encountered the following error while running ${
arguments[1].command.name
}: ${errorID.toString()} - Sentry report: https://sentry.io/${sentry}`,
);

if (message.channel || message)
await message.channel.send({
content: `Failed to execute this command. Report this error ID (\`${errorID}\`) to a developer.`,
});
await functions.sendWebhook(config.webhooks.errors.id, config.webhooks.errors.token, { embeds: [errorEmbed] });
return;
}
}
}
17 replies
SIASapphire - Imagine a framework
Created by Hyper on 7/16/2023 in #sapphire-support
Subcommand issues
I'm having an issue with subcommands where it just doesn't seem to recognize a subcommand. The following is how I register the command I'm having issues with. All of them work fine except guild whitelist. That one throws this error: https://hyperfire-dev.sentry.io/share/issue/1464c7085b934a0296005c7e7ee22553/
@ApplyOptions<Subcommand.Options>({
name: 'access',
preconditions: ['BotDeveloper'],
description: 'Manage access control.',
aliases: ['accesscontrol'],
subcommands: [
{
name: 'help',
default: true,
type: 'method',
messageRun: 'help'
},

{
name: 'user',
type: 'group',
entries: [
{
name: 'blacklist',
type: 'method',
messageRun: 'userBlacklistRun'
}
]
},

/*{
name: 'guild whitelist',
messageRun: 'guildWhitelistRun'
},
{
name: 'guild blacklist',
messageRun: 'guildBlacklistRun'
}*/

{
name: 'guild',
type: 'group',
entries: [
{
name: 'blacklist',
type: 'method',
messageRun: 'guildBlacklistRun'
},
{
name: 'whitelist',
type: 'method',
messageRun: 'guildWhitelistRun'
}
]
}
]
})
@ApplyOptions<Subcommand.Options>({
name: 'access',
preconditions: ['BotDeveloper'],
description: 'Manage access control.',
aliases: ['accesscontrol'],
subcommands: [
{
name: 'help',
default: true,
type: 'method',
messageRun: 'help'
},

{
name: 'user',
type: 'group',
entries: [
{
name: 'blacklist',
type: 'method',
messageRun: 'userBlacklistRun'
}
]
},

/*{
name: 'guild whitelist',
messageRun: 'guildWhitelistRun'
},
{
name: 'guild blacklist',
messageRun: 'guildBlacklistRun'
}*/

{
name: 'guild',
type: 'group',
entries: [
{
name: 'blacklist',
type: 'method',
messageRun: 'guildBlacklistRun'
},
{
name: 'whitelist',
type: 'method',
messageRun: 'guildWhitelistRun'
}
]
}
]
})
10 replies
SIASapphire - Imagine a framework
Created by Hyper on 7/9/2023 in #sapphire-support
Application Data is null
So, I'm trying to get the owners of my application (for a team-members-based precondition for stuff like eval) but this.container.client.application has most of the data as null. It gives me the ID, flags, and that's about it. Is there anything I need to do to get that to show? Sorry if this is a stupid question it's been a while since I've worked with discord bots
6 replies
SIASapphire - Imagine a framework
Created by Hyper on 2/25/2023 in #sapphire-support
Preventing Commands in DMs
How do you prevent commands from being used in DMs? Message commands.
26 replies
SIASapphire - Imagine a framework
Created by Hyper on 1/9/2023 in #sapphire-support
Issue on upgrade to v4
On loading like any file (listeners and commands) it spits out a TypeError: import_discord2.Permissions is not a constructor error and doesn't load it.
48 replies