Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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_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)
- })
- 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
- })
- })
- // warn.js
- const fs = require('fs')
- module.exports = {
- run: async (message, args, client) => {
- if (!message.member.hasPermission('MANAGE_MESSAGES')) return message.channel.send('Vous n\'avez pas la permission d\'utiliser cette commande.')
- const member = message.mentions.members.first()
- if (!member) return message.channel.send('Veuillez mentionner le membre à warn.')
- if (member.id === message.guild.ownerID) return message.channel.send('Vous ne pouvez pas warn le propriétaire du serveur.')
- if (message.member.roles.highest.comparePositionTo(member.roles.highest) < 1 && message.author.id !== message.guild.ownerID) return message.channel.send('Vous ne pouvez pas warn ce membre.')
- const reason = args.slice(1).join(' ')
- if (!reason) return message.channel.send('Veuillez indiquer une raison.')
- if (!client.db.warns[member.id]) client.db.warns[member.id] = []
- client.db.warns[member.id].unshift({
- reason,
- date: Date.now(),
- mod: message.author.id
- })
- fs.writeFileSync('./db.json', JSON.stringify(client.db))
- message.channel.send(`${member} a été warn pour ${reason} !`)
- },
- name: 'warn',
- guildOnly: true
- }
- // infractions.js
- const moment = require('moment'),
- Discord = require('discord.js')
- moment.locale('fr')
- module.exports = {
- run: async (message, args, client) => {
- if (!message.member.hasPermission('MANAGE_MESSAGES')) return message.channel.send('Vous n\'avez pas la permission d\'utiliser cette commande.')
- const member = message.mentions.members.first()
- if (!member) return message.channel.send('Veuillez mentionner le membre dont voir les warns.')
- if (!client.db.warns[member.id]) return message.channel.send('Ce membre n\'a aucun warn.')
- message.channel.send(new Discord.MessageEmbed()
- .setDescription(`**Total de warns :** ${client.db.warns[member.id].length}\n\n__**10 derniers warns**__\n\n${client.db.warns[member.id].slice(0, 10).map((warn, i) => `**${i + 1}.** ${warn.reason}\nSanctionné ${moment(warn.date).fromNow()} par <@!${warn.mod}>`).join('\n\n')}`))
- },
- name: 'infractions',
- guildOnly: true
- }
- // unwarn.js
- const fs = require('fs')
- module.exports = {
- run: async (message, args, client) => {
- if (!message.member.hasPermission('MANAGE_MESSAGES')) return message.channel.send('Vous n\'avez pas la permission d\'utiliser cette commande.')
- const member = message.mentions.members.first()
- if (!member) return message.channel.send('Veuillez mentionner le membre à unwarn.')
- if (!client.db.warns[member.id]) return message.channel.send('Ce membre n\'a aucun warn.')
- const warnIndex = parseInt(args[1], 10) - 1
- if (warnIndex < 0 || !client.db.warns[member.id][warnIndex]) return message.channel.send('Ce warn n\'existe pas.')
- const { reason } = client.db.warns[member.id].splice(warnIndex, 1)[0]
- if (!client.db.warns[member.id].length) delete client.db.warns[member.id]
- fs.writeFileSync('./db.json', JSON.stringify(client.db))
- message.channel.send(`${member} a été unwarn pour ${reason} !`)
- },
- name: 'unwarn',
- guildOnly: true
- }
- // db.json
- {"warns":{}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement