Last active
June 26, 2022 23:35
-
-
Save iamnotacoder-djs/e93fb7f04433fc760468369d5d2d9591 to your computer and use it in GitHub Desktop.
Discord.js@13.8.0 Banner Changer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Client, Intents, MessageEmbed, MessageActionRow, MessageButton } = require('discord.js'), | |
client = new Client({ intents: [Intents.FLAGS.GUILDS ] }), | |
fs = require('fs'); | |
client.login("your bot token") | |
.then(() => { | |
client.db = require('quick.db'); // quick.db@^7.1.3 | |
timeout1h(); | |
}); | |
async function timeout1h() { | |
setTimeout(timeout1h, 1000 * 60 * 60); | |
const date = new Date(); | |
const lastHour = client.db.get(`banner.last.hour`) ?? 0, | |
lastName = client.db.get(`banner.last.name`) ?? `meme1.png`; | |
if (lastHour != date.getHours()) { | |
client.db.set(`banner.last.hour`, date.getHours()); | |
client.guilds.fetch("any guild_id") | |
.then((guild) => { | |
if (guild.premiumSubscriptionCount >= 7) { | |
let files = fs.readdirSync('./banners/') | |
let randomFile = files[Math.floor(Math.random() * files.length)], | |
nextFileByName = files[0], | |
found = files.findIndex((el) => { return el == lastName; }); | |
if (found == -1) nextFileByName = `meme1.png`; | |
if (found < files.length - 1) nextFileByName = files[found + 1]; | |
if (found === files.length - 1) nextFileByName = files[0]; | |
client.db.set(`banner.last.name`, nextFileByName); | |
guild.setBanner(`./banners/${nextFileByName}`) | |
.then((updated) => { | |
// do nothing | |
}) | |
.catch(console.log); | |
} | |
}).catch(console.log); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment