This code is not running on sapphire

const { Listener } = require("@sapphire/framework");
const { ActivityType } = require("discord.js");
const ms = require("ms");

class ReadyListener extends Listener {
run(client) {
console.log(`${client.user.tag} is online!`);

let statuses = [
{ name: `status name 1`, type: ActivityType.Watching },
{ name: `status name 2`, type: ActivityType.Listening },
];

let currentStatus = 0;

setInterval(() => {
client.user.setPresence({
activities: [statuses[currentStatus]],
});

currentStatus = (currentStatus + 1) % statuses.length;
}, ms("13"));
}
}

module.exports = {
ReadyListener,
};
const { Listener } = require("@sapphire/framework");
const { ActivityType } = require("discord.js");
const ms = require("ms");

class ReadyListener extends Listener {
run(client) {
console.log(`${client.user.tag} is online!`);

let statuses = [
{ name: `status name 1`, type: ActivityType.Watching },
{ name: `status name 2`, type: ActivityType.Listening },
];

let currentStatus = 0;

setInterval(() => {
client.user.setPresence({
activities: [statuses[currentStatus]],
});

currentStatus = (currentStatus + 1) % statuses.length;
}, ms("13"));
}
}

module.exports = {
ReadyListener,
};
Solution:
figured it out, to anyone else that has this problem just add async before the run and also add this code before the async run(client) {} part ```js constructor(context, options) { super(context, {...
Jump to solution
3 Replies
kyra
kyra•2y ago
I don't think the pieces loader really loads properties from module.exports, only exports.* and module.exports Try module.exports = ReadyListener; or exports.ReadyListener = ReadyListener; Alternatively, if you can make the switch to ESM, you'll be able to do export class ReadyListener ..., which may look less boilerplate-y
Solution
-Carlos👑
-Carlos👑•2y ago
figured it out, to anyone else that has this problem just add async before the run and also add this code before the async run(client) {} part
constructor(context, options) {
super(context, {
...options,
once: true,
});
}
constructor(context, options) {
super(context, {
...options,
once: true,
});
}
there was also missing s in ms() (below currentStatus = (currentStatus + 1) % statuses.length;)
Favna
Favna•2y ago
async doesnt matter if the function doesnt await anything. You should learn what async actually does before you add it to any place willy nilly. Adding the constructor is purely optional, though you would want to run the ready listener only once so it's a good addition nonetheless. the syntax error however is an issue because when JS encounters a syntax error it will simply not execute the code we do support this export syntax.
Want results from more Discord servers?
Add your server