Stev
Stev
Explore posts from servers
SIASapphire - Imagine a framework
Created by Stev on 6/21/2023 in #sapphire-support
Sapphire-like Listeners for other Emitters, such as ShardManager?
Probably a stupid question, but I've looked and haven't found any. Does Sapphire support listeners for other emitters? For example, if I want to listen for the shardCreate event of ShardManager. Sapphire makes event handling so simple, so I figured I'd hope that there is, instead of going manual. Thanks!
5 replies
SIASapphire - Imagine a framework
Created by Stev on 5/11/2023 in #sapphire-support
Custom Events not Creating Listeners
I'm having issues using Sapphire with custom events. For example, I have an event for when a member subscribes to a role:
import { ApplyOptions } from '@sapphire/decorators';
import { container, Listener } from '@sapphire/framework';
import { type GuildMember } from 'discord.js';

const commandOptions = { event: 'guildMemberUpdate' };

@ApplyOptions<Listener.Options>(commandOptions)
export class ListenerExt extends Listener {
public async run(oldGuildMember: GuildMember, newGuildMember: GuildMember) {
// ! Subscriber events.
// Check if the guild member is premium.
const isPremium = newGuildMember.roles.cache.some((role) => role.tags?.premiumSubscriberRole);

// Check if the guild member was premium.
const wasPremium = oldGuildMember.roles.cache.some((role) => role.tags?.premiumSubscriberRole);

// Check if the guild member's premiums status changed.
if (isPremium && !wasPremium) {
container.client.emit('guildMemberSubscribed', newGuildMember);
} else if (!isPremium && wasPremium) {
container.client.emit('guildMemberUnsubscribed', newGuildMember);
}
}
}
import { ApplyOptions } from '@sapphire/decorators';
import { container, Listener } from '@sapphire/framework';
import { type GuildMember } from 'discord.js';

const commandOptions = { event: 'guildMemberUpdate' };

@ApplyOptions<Listener.Options>(commandOptions)
export class ListenerExt extends Listener {
public async run(oldGuildMember: GuildMember, newGuildMember: GuildMember) {
// ! Subscriber events.
// Check if the guild member is premium.
const isPremium = newGuildMember.roles.cache.some((role) => role.tags?.premiumSubscriberRole);

// Check if the guild member was premium.
const wasPremium = oldGuildMember.roles.cache.some((role) => role.tags?.premiumSubscriberRole);

// Check if the guild member's premiums status changed.
if (isPremium && !wasPremium) {
container.client.emit('guildMemberSubscribed', newGuildMember);
} else if (!isPremium && wasPremium) {
container.client.emit('guildMemberUnsubscribed', newGuildMember);
}
}
}
Then, in another Sapphire listener:
import { ApplyOptions } from '@sapphire/decorators';
import { Listener } from '@sapphire/framework';
import { type GuildMember } from 'discord.js';

const commandOptions = { event: 'guildMemberUnsubscribed' };

@ApplyOptions<Listener.Options>(commandOptions)
export class ListenerExt extends Listener {
public async run(guildMember: GuildMember) {
// Remove all perks from the guild member.
}
}
import { ApplyOptions } from '@sapphire/decorators';
import { Listener } from '@sapphire/framework';
import { type GuildMember } from 'discord.js';

const commandOptions = { event: 'guildMemberUnsubscribed' };

@ApplyOptions<Listener.Options>(commandOptions)
export class ListenerExt extends Listener {
public async run(guildMember: GuildMember) {
// Remove all perks from the guild member.
}
}
My issue is that with custom named events, Sapphire doesn't seem to register all of them. For example, I'll have guildMemberDemoted, guildMemberPromoted, guildMemberSubscribed, and guildMemberUnsubscribed. guildMemberDemoted will fire off, but guildMemberPromoted does not. If I check the client for a guildMemberPromoted listener, none exists. I thought maybe I'd have to increase the max listeners for the client, but that also doesn't work. Any ideas?
7 replies
SIASapphire - Imagine a framework
Created by Stev on 2/16/2023 in #sapphire-support
Registering commands and other paths
Hi guys! I'm having some troubles. When I use sapphire new, everything works as intended. The commands in the commands directory are registered properly. However, if I do not use sapphire new and try to add it to an existing project, without sapphire init, it doesn't register the commands. After looking into it, and logging the stores, I see that the paths should be C:/.../myProject/bin/commands, but the path is showing C:/.../myProject/commands. Even if I copy the .sapphirerc.json from the other working one. Why does this happen? I've tried using sapphire init with the same problem - it looks a directory up. I cannot see anywhere in the working project, using sapphire new, where any additional configuration is added. Thanks!
5 replies