fluffy
fluffy
Explore posts from servers
SIASapphire - Imagine a framework
Created by fluffy on 10/23/2024 in #sapphire-support
Logger - log to txt file
I am trying to use this to clone console.log logs to a txt file. Any way I can do the same for the sapphire logger as well? Thanks.
import * as fs from "fs";

const filePath = `./logs/console/${new Date().toISOString().replace(/:/g, "_")}.txt`;
const logStream = fs.createWriteStream(filePath, { flags: "a" }); // Append mode

const originalLog = console.log;
console.log = function(msg) {
logStream.write(`${msg}\n`);
originalLog.apply(console, msg);
};
import * as fs from "fs";

const filePath = `./logs/console/${new Date().toISOString().replace(/:/g, "_")}.txt`;
const logStream = fs.createWriteStream(filePath, { flags: "a" }); // Append mode

const originalLog = console.log;
console.log = function(msg) {
logStream.write(`${msg}\n`);
originalLog.apply(console, msg);
};
4 replies
SIASapphire - Imagine a framework
Created by fluffy on 7/11/2024 in #sapphire-support
Cooldown filter precondition
I wish to create a cooldown for a command but instead of filtering by user (cooldownFilteredUsers), I want to filter it with a precondition (ie user has a certain role in the guild). What is the best way to do this? (I don't want to deny the command usage, just apply a cooldown for users who do not meet the precondition.)
9 replies
SIASapphire - Imagine a framework
Created by fluffy on 7/3/2024 in #sapphire-support
PaginatedMessage - change select menu string names
Hi, I want to change the string names in the paginated message select menu. Instead of "page 1" "page 2" I want a custom string based on the embed content. I've looked through the documents and don't see any string to change under PaginatedMessage.defaultActions. Thanks!
4 replies
SIASapphire - Imagine a framework
Created by fluffy on 4/2/2024 in #sapphire-support
Stricter type checking for string command choices
Hi, was wondering if this is possible. In this example I am doing a command that can change my bot's status from Online to Invisible/Idle/Dnd. I want to ensure that the value choices in addChoices have the PresenceStatusData type in case the string values are changed in a future API.
import { ApplicationCommandRegistry, Command } from "@sapphire/framework";
import { ChatInputCommandInteraction, PresenceStatusData } from "discord.js";

// ...

public override registerApplicationCommands(registry: ApplicationCommandRegistry) {
registry.registerChatInputCommand(builder =>
builder
.setName(this.name)
.setDescription(this.description)
.addStringOption(option =>
option
.setName("status")
.setDescription("Online status")
.setRequired(true)
.addChoices( // possible to do stricter type checking for value?
{ name: "Online", value: "online" },
{ name: "Idle", value: "idle" },
{ name: "Do Not Disturb", value: "dnd" },
{ name: "Offline", value: "invisible" },
)
)
);
}
import { ApplicationCommandRegistry, Command } from "@sapphire/framework";
import { ChatInputCommandInteraction, PresenceStatusData } from "discord.js";

// ...

public override registerApplicationCommands(registry: ApplicationCommandRegistry) {
registry.registerChatInputCommand(builder =>
builder
.setName(this.name)
.setDescription(this.description)
.addStringOption(option =>
option
.setName("status")
.setDescription("Online status")
.setRequired(true)
.addChoices( // possible to do stricter type checking for value?
{ name: "Online", value: "online" },
{ name: "Idle", value: "idle" },
{ name: "Do Not Disturb", value: "dnd" },
{ name: "Offline", value: "invisible" },
)
)
);
}
8 replies
SIASapphire - Imagine a framework
Created by fluffy on 1/30/2023 in #sapphire-support
Recognising "hidden" in CommandOptions
5 replies
SIASapphire - Imagine a framework
Created by fluffy on 1/18/2023 in #sapphire-support
Subcommand unintentionally triggers Events.MessageCommandRun
I have a /dpm subcommand is defined as:
subcommands: [
{ name: "all", chatInputRun: "dpmAll" },
{ name: "job", chatInputRun: "dpmJob" },
{ name: "ign", chatInputRun: "dpmIgn" }
]
subcommands: [
{ name: "all", chatInputRun: "dpmAll" },
{ name: "job", chatInputRun: "dpmJob" },
{ name: "ign", chatInputRun: "dpmIgn" }
]
I noticed a strange occurence where, if my message command prefix is set to /, and I run /dpm as a message, the MessageCommandRun event will be triggered and gives this error, even though I never registered a messageRun method.
UserError: No subcommand was matched with the provided arguments.
UserError: No subcommand was matched with the provided arguments.
Wondering if this is intended or am I doing something wrong?
7 replies