Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // db.json
- {"warns":{},"tickets":{},"lockedChannels":[]}
- // config.json
- {
- "token": "votre token",
- "prefix": "!",
- "greeting": {
- "channel": "718970110164992041",
- "role": "718970160647635056"
- },
- "reactionRole": {
- "721812281347932311": {
- "emojis": [{
- "id": "719563468008718348",
- "roles": "722404495371534358"
- }]
- },
- "721812680763244596": {
- "removable": true,
- "emojis": [{
- "name": "💻",
- "roles": ["722088168458813584", "722088234963828747"]
- }, {
- "name": "🎮",
- "roles": "722088255402672139"
- }]
- }
- },
- "cooldown": {
- "723998402395767288": 1e4,
- "723998419986808883": 3e4
- },
- "ticket": {
- "category": "741691177807380552",
- "roles": ["741690852719460463", "741690932164034670"]
- },
- "serverStats": {
- "humans": "753290521094520963",
- "bots": "753290543395635260",
- "total": "753290560181108886"
- }
- }
- // index.js
- const Discord = require('discord.js'),
- client = new Discord.Client({
- fetchAllMembers: true,
- partials: ['MESSAGE', 'REACTION']
- }),
- config = require('./config.json'),
- fs = require('fs'),
- humanizeDuration = require('humanize-duration'),
- cooldown = new Set()
- client.login(config.token)
- client.commands = new Discord.Collection()
- client.db = require('./db.json')
- fs.readdir('./commands', (err, files) => {
- if (err) throw err
- files.forEach(file => {
- if (!file.endsWith('.js')) return
- const command = require(`./commands/${file}`)
- client.commands.set(command.name, command)
- })
- })
- client.on('message', message => {
- if (message.type !== 'DEFAULT' || message.author.bot) return
- if (!message.member.hasPermission('MANAGE_CHANNELS') && client.db.lockedChannels.includes(message.channel.id)) return message.delete()
- if (!message.member.hasPermission('MANAGE_MESSAGES')) {
- const duration = config.cooldown[message.channel.id]
- if (duration) {
- const id = `${message.channel.id}_${message.author.id}`
- if (cooldown.has(id)) {
- message.delete()
- return message.channel.send(`Ce salon est soumis a un cooldown de ${humanizeDuration(duration, {language: 'fr'})}.`).then(sent => sent.delete({timeout: 5e3}))
- }
- cooldown.add(id)
- setTimeout(() => cooldown.delete(id), duration)
- }
- }
- const args = message.content.trim().split(/ +/g)
- const commandName = args.shift().toLowerCase()
- if (!commandName.startsWith(config.prefix)) return
- const command = client.commands.get(commandName.slice(config.prefix.length))
- if (!command) return
- if (command.guildOnly && !message.guild) return message.channel.send('Cette commande ne peut être utilisée que dans un serveur.')
- command.run(message, args, client)
- })
- client.on('guildMemberAdd', member => {
- member.guild.channels.cache.get(config.greeting.channel).send(`${member}`, new Discord.MessageEmbed()
- .setDescription(`${member} a rejoint le serveur. Nous sommes désormais ${member.guild.memberCount} ! 🎉`)
- .setColor('#00ff00'))
- member.roles.add(config.greeting.role)
- })
- client.on('guildMemberRemove', member => {
- member.guild.channels.cache.get(config.greeting.channel).send(new Discord.MessageEmbed()
- .setDescription(`${member.user.tag} a quitté le serveur... 😢`)
- .setColor('#ff0000'))
- })
- client.on('messageReactionAdd', (reaction, user) => {
- if (!reaction.message.guild || user.bot) return
- const reactionRoleElem = config.reactionRole[reaction.message.id]
- if (!reactionRoleElem) return
- const prop = reaction.emoji.id ? 'id' : 'name'
- const emoji = reactionRoleElem.emojis.find(emoji => emoji[prop] === reaction.emoji[prop])
- if (emoji) reaction.message.guild.member(user).roles.add(emoji.roles)
- else reaction.users.remove(user)
- })
- client.on('messageReactionRemove', (reaction, user) => {
- if (!reaction.message.guild || user.bot) return
- const reactionRoleElem = config.reactionRole[reaction.message.id]
- if (!reactionRoleElem || !reactionRoleElem.removable) return
- const prop = reaction.emoji.id ? 'id' : 'name'
- const emoji = reactionRoleElem.emojis.find(emoji => emoji[prop] === reaction.emoji[prop])
- if (emoji) reaction.message.guild.member(user).roles.remove(emoji.roles)
- })
- client.on('ready', () => {
- const statuses = [
- () => `${client.guilds.cache.size} serveurs`,
- () => `${client.guilds.cache.reduce((acc, guild) => acc + guild.memberCount, 0)} utilisateurs`
- ]
- let i = 0
- setInterval(() => {
- client.user.setActivity(statuses[i](), {type: 'PLAYING'})
- i = ++i % statuses.length
- }, 1e4)
- setInterval(() => {
- const [bots, humans] = client.guilds.cache.first().members.cache.partition(member => member.user.bot)
- client.channels.cache.get(config.serverStats.humans).setName(`Humains : ${humans.size}`)
- client.channels.cache.get(config.serverStats.bots).setName(`🤖 Bots : ${bots.size}`)
- client.channels.cache.get(config.serverStats.total).setName(`Total : ${client.guilds.cache.first().memberCount}`)
- }, 3e4)
- })
- client.on('channelCreate', channel => {
- if (!channel.guild) return
- const muteRole = channel.guild.roles.cache.find(role => role.name === 'Muted')
- if (!muteRole) return
- channel.createOverwrite(muteRole, {
- SEND_MESSAGES: false,
- CONNECT: false,
- ADD_REACTIONS: false
- })
- })
- // lock.js
- const fs = require('fs')
- module.exports = {
- run: (message, args, client) => {
- if (!message.member.hasPermission('MANAGE_CHANNELS')) return message.channel.send('Vous n\'avez pas la permission d\'utiliser cette commande.')
- const channel = message.mentions.channels.first() || message.channel
- if (client.db.lockedChannels.includes(channel.id)) return message.channel.send('Ce salon est déjà vérrouillé.')
- client.db.lockedChannels.push(channel.id)
- fs.writeFileSync('./db.json', JSON.stringify(client.db))
- message.channel.send('Ce salon a été verrouillé !')
- },
- name: 'lock',
- guildOnly: true
- }
- // unlock.js
- const fs = require('fs')
- module.exports = {
- run: (message, args, client) => {
- if (!message.member.hasPermission('MANAGE_CHANNELS')) return message.channel.send('Vous n\'avez pas la permission d\'utiliser cette commande.')
- const channel = message.mentions.channels.first() || message.channel
- if (!client.db.lockedChannels.includes(channel.id)) return message.channel.send('Ce salon n\'est pas vérrouillé.')
- client.db.lockedChannels.splice(client.db.lockedChannels.indexOf(channel.id), 1)
- fs.writeFileSync('./db.json', JSON.stringify(client.db))
- message.channel.send('Ce salon a été déverrouillé !')
- },
- name: 'unlock',
- guildOnly: true
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement