Advertisement
ala89

TUTO DEV #1 - CREER UN BOT DISCORD : LES PRÉREQUIS

Jun 6th, 2020 (edited)
14,683
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // index.js :
  2. const Discord = require('discord.js'),
  3.     client = new Discord.Client({
  4.         fetchAllMembers: true
  5.     }),
  6.     config = require('./config.json'),
  7.     fs = require('fs')
  8.  
  9. client.login(config.token)
  10. client.commands = new Discord.Collection()
  11.  
  12. fs.readdir('./commands', (err, files) => {
  13.     if (err) throw err
  14.     files.forEach(file => {
  15.         if (!file.endsWith('.js')) return
  16.         const command = require(`./commands/${file}`)
  17.         client.commands.set(command.name, command)
  18.     })
  19. })
  20.  
  21. client.on('message', message => {
  22.     if (message.type !== 'DEFAULT' || message.author.bot) return
  23.  
  24.     const args = message.content.trim().split(/ +/g)
  25.     const commandName = args.shift().toLowerCase()
  26.     if (!commandName.startsWith(config.prefix)) return
  27.     const command = client.commands.get(commandName.slice(config.prefix.length))
  28.     if (!command) return
  29.     command.run(message, args, client)
  30. })
  31.  
  32. // config.json
  33. {
  34.     "token": "votre token",
  35.     "prefix": "!"
  36. }
  37.  
  38. // bonjour.js
  39. module.exports = {
  40.     run: message => message.channel.send('bonjour à toi'),
  41.     name: 'bjr'
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement