Advertisement
ala89

TUTO DEV #3 - CREER UN BOT DISCORD : CREER DES EMBEDS

Jun 14th, 2020 (edited)
6,873
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. client.on('guildMemberAdd', member => {
  33.     member.guild.channels.cache.get(config.greeting.channel).send(`${member}`, new Discord.MessageEmbed()
  34.         .setDescription(`${member} a rejoint le serveur. Nous sommes désormais ${member.guild.memberCount} ! 🎉`)
  35.         .setColor('#00ff00'))
  36.     member.roles.add(config.greeting.role)
  37. })
  38.  
  39. client.on('guildMemberRemove', member => {
  40.     member.guild.channels.cache.get(config.greeting.channel).send(new Discord.MessageEmbed()
  41.         .setDescription(`${member.user.tag} a quitté le serveur... 😢`)
  42.         .setColor('#ff0000'))
  43. })
  44.  
  45. // embed.js
  46. const Discord = require('discord.js')
  47.  
  48. module.exports = {
  49.     run: message => {
  50.         message.channel.send(new Discord.MessageEmbed()
  51.             .setTitle('Mon titre')
  52.             .setTitle('Autre titre **bonjour**')
  53.             .setDescription('[Recherche Google](https://google.fr) **bonjour**')
  54.             .setColor('RANDOM')
  55.             .addField('Champ 1 **bonjour**', 'Bonjour c\'est moi **bonjour**', true)
  56.             .addField('Champ 2', 'Blabla', true)
  57.             .setAuthor('ala89 **bonjour**', 'https://cdn.discordapp.com/attachments/718476721418141728/719563110154764298/logo.png', 'https://google.fr')
  58.             .setImage('https://cdn.discordapp.com/attachments/718476721418141728/719563122960236644/thumb.png')
  59.             .setThumbnail('https://cdn.discordapp.com/attachments/718476721418141728/719563110154764298/logo.png')
  60.             .setFooter('Mon bot perso **bonjour**', 'https://cdn.discordapp.com/attachments/718476721418141728/719563110154764298/logo.png')
  61.             .setTimestamp()
  62.             .setURL('https://google.fr'))
  63.     },
  64.     name: 'embed'
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement