Haha-Yes/events/client/status.js

41 lines
1.3 KiB
JavaScript
Raw Normal View History

2023-04-05 17:47:02 +02:00
import { ActivityType } from 'discord.js';
2022-08-15 15:14:25 +02:00
import game from '../../json/playing.json' assert {type: 'json'};
import watch from '../../json/watching.json' assert {type: 'json'};
export default {
name: 'ready',
once: true,
async execute(client) {
// Bot status
2023-04-05 17:47:02 +02:00
await setStatus();
2022-08-15 15:14:25 +02:00
// Change status every 30 minutes
setInterval(async () => {
2023-04-05 17:47:02 +02:00
await setStatus();
2022-08-15 15:14:25 +02:00
}, 1800000);
async function setStatus() {
const random = Math.floor((Math.random() * 2));
2023-04-05 17:47:02 +02:00
let types, status;
2022-08-15 15:14:25 +02:00
// Random "Watching" status taken from json
if (random === 0) {
console.log('Status type: \x1b[32mWatching\x1b[0m');
2023-04-05 17:47:02 +02:00
status = watch[Math.floor((Math.random() * watch.length))];
2022-08-16 21:12:49 +02:00
status = status + ' | Now with slash commands!';
2022-08-15 15:14:25 +02:00
console.log(`Setting status to: ${status}`);
2023-04-05 17:47:02 +02:00
types = [ ActivityType.Watching ];
2022-08-15 15:14:25 +02:00
}
// Random "Playing" status taken from json
else if (random === 1) {
console.log('Status type: \x1b[32mPlaying\x1b[0m');
2023-04-05 17:47:02 +02:00
status = game[Math.floor((Math.random() * game.length))];
2022-08-16 21:12:49 +02:00
status = status + ' | Now with slash commands!';
2022-08-15 15:14:25 +02:00
console.log(`Setting status to: ${status}`);
2023-04-05 17:47:02 +02:00
types = [ ActivityType.Playing, ActivityType.Competing ];
2022-08-15 15:14:25 +02:00
}
2023-04-05 17:47:02 +02:00
await client.user.setActivity(status, { type: types[Math.floor((Math.random() * types.length))] });
2022-08-15 15:14:25 +02:00
}
},
};