Dolliwyx
Dolliwyx
SIASapphire - Imagine a framework
Created by Dolliwyx on 11/24/2023 in #sapphire-support
Cannot set properties of undefined when extending `container`
Hello! I wanted to create a property entities that holds two properties which would be users and guild of class Entity. Now entities doesn't have any type at all since it'll just be an object to hold users and guild in one. But whenever I run my bot I receive Cannot set properties of undefined (setting 'users') Here's my augments:
declare module '@sapphire/pieces' {
interface Container {
entities: {
users: Entity<UserModel>;
guilds: Entity<GuildModel>;
};
}
}
declare module '@sapphire/pieces' {
interface Container {
entities: {
users: Entity<UserModel>;
guilds: Entity<GuildModel>;
};
}
}
And here's it is being initialized in setup.ts
container.entities.users = new Entity({});
container.entities.guilds = new Entity({});
container.entities.users = new Entity({});
container.entities.guilds = new Entity({});
I tried moving the initialization inside my Client but I get the same error. Perhaps I'm missing something? Thank you for the help!
8 replies
SIASapphire - Imagine a framework
Created by Dolliwyx on 8/23/2023 in #sapphire-support
Async Preconditions
Helloo! It seems that I am unable to create a precondition that is async, whenever I try to write one with async. I get The inferred type of 'chatInputRun' cannot be named without a reference to '.pnpm/@[email protected]/node_modules/@sapphire/result'. This is likely not portable. A type annotation is necessary. Here is the code in question:
public override async chatInputRun(interaction: Interaction) {
const guildPlayer = this.container.queue.get(interaction.guildId!);
if (!guildPlayer) return this.ok();
const {
music: { djs }
} = await this.container.settings.getUserSetting(guildPlayer.owner);

if (guildPlayer.owner !== interaction.user.id && !djs?.includes(interaction.user.id)) {
return this.error({
message: 'The owner of this music session does not have you as a DJ. Have them add you using `/dj add`!',
identifier: 'PermissionsMissing'
});
}
return this.ok();
}
public override async chatInputRun(interaction: Interaction) {
const guildPlayer = this.container.queue.get(interaction.guildId!);
if (!guildPlayer) return this.ok();
const {
music: { djs }
} = await this.container.settings.getUserSetting(guildPlayer.owner);

if (guildPlayer.owner !== interaction.user.id && !djs?.includes(interaction.user.id)) {
return this.error({
message: 'The owner of this music session does not have you as a DJ. Have them add you using `/dj add`!',
identifier: 'PermissionsMissing'
});
}
return this.ok();
}
19 replies
SIASapphire - Imagine a framework
Created by Dolliwyx on 8/22/2023 in #sapphire-support
Sample implementation of per-subcommand preconditions
Hello! Are there any examples on how would I be able to implement the new feature? And I suppose this supports both interaction and message preconditions? And would this be a better option instead of using precondition decorators? Thank you!
8 replies
SIASapphire - Imagine a framework
Created by Dolliwyx on 8/21/2023 in #sapphire-support
Question about "runIn" preconditions
Hello! According to the docs regarding setting the channel types a command can run in. In theory setting the command's runIn to
// ...
runIn: [CommandOptionsRunTypeEnum.GuildText, CommandOptionsRunTypeEnum.GuildVoice]
// ...
// ...
runIn: [CommandOptionsRunTypeEnum.GuildText, CommandOptionsRunTypeEnum.GuildVoice]
// ...
Should make the command run in both text channels and voice based text channels. However, setting it like this, doesn't allow me to run them to both channel types. What I can do was to only set one channel type in runIn and it'd work for that particular channel type only. How can I make it so that I can allow the command to run in both channel types?
9 replies
SIASapphire - Imagine a framework
Created by Dolliwyx on 8/6/2023 in #sapphire-support
Interaction and Message Function Preconditions
Hey! Is it possible to create function preconditions for both interactions and messages under the same exported decorator? Or do I have create different exports for each of them? Alternatively, would I be able to create such function precondition that accepts both messages and interactions?
12 replies
SIASapphire - Imagine a framework
Created by Dolliwyx on 7/19/2023 in #sapphire-support
Regarding containers
Hello! With regards to the example repos with setup.ts, is every property in the container already available like the Client at startup?
6 replies
SIASapphire - Imagine a framework
Created by Dolliwyx on 12/24/2022 in #discordjs-support
Varying parsing options?
With slash commands, is it possible to have a varying input option depending on a condition? Say there are two input options: The first one may ask for a channel or a role The second one would then take a channel or a role depending on what the user picked on the first argument
10 replies
SIASapphire - Imagine a framework
Created by Dolliwyx on 12/23/2022 in #sapphire-support
Handling argument autocomplete per command
Would it be possible to handle autocompletes through the Command class itself instead and it will be handled accordingly by the interactionCreate event?
10 replies