ala89

TUTO DEV #11 - CREER UN BOT DISCORD : CLEAR ET HELP

Aug 23rd, 2020 (edited)
6,960
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // clear.js
  2. module.exports = {
  3.     run: async (message, args) => {
  4.         if (!message.member.hasPermission('MANAGE_MESSAGES')) return message.channel.send('Vous n\'avez pas la permission d\'utiliser cette commande.')
  5.         const count = args[0]
  6.         if (!/\d+/.test(count)) return message.channel.send('Veuillez indiquer un nombre de messages à supprimer.')
  7.         if (count < 1 || count > 99) return message.channel.send('Le nombre de message doit être compris entre 1 et 99.')
  8.         const { size } = await message.channel.bulkDelete(Number(count) + 1, true)
  9.         message.channel.send(`${size - 1} messages ont été supprimés !`).then(sent => sent.delete({timeout: 5e3}))
  10.     },
  11.     name: 'clear',
  12.     guildOnly: true
  13. }
  14.  
  15. // help.js
  16. const Discord = require('discord.js'),
  17.     config = require('../config.json')
  18.  
  19. module.exports = {
  20.     run: (message, args, client) => {
  21.         if (args[0]) {
  22.             const command = client.commands.get(args[0].toLowerCase())
  23.             if (!command || !command.help) return message.channel.send('Cette commande n\'existe pas.')
  24.             message.channel.send(new Discord.MessageEmbed()
  25.                 .setDescription(`**Commande : ${command.name}**\n\n${command.help.description}\n\nSyntaxe : \`${config.prefix}${command.name}${command.help.syntax ? ` ${command.help.syntax}` : ''}\``))
  26.         }
  27.         else {
  28.             message.channel.send(new Discord.MessageEmbed()
  29.                 .setTitle('Liste des commandes')
  30.                 .setDescription(`${client.commands.filter(command => command.help).map(command => `\`${config.prefix}${command.name}\``).join(' ')}\n\nPour plus d'informations sur une commande, tapez \`${config.prefix}help [nom de la commande]\``))
  31.        }
  32.    },
  33.    name: 'help',
  34.    help: {
  35.        description: 'Cette commande permet d\'avoir de l\'aide.',
  36.         syntax: '[nom de la commande]'
  37.     }
  38. }
Add Comment
Please, Sign In to add comment