From df40fa0f589cc7ea4451be1c9cdd429ee39f51f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Bersier?= Date: Thu, 9 May 2019 21:33:52 +0200 Subject: [PATCH] welcome message for new user --- event/listeners/guildMemberAdd.js | 45 +++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 event/listeners/guildMemberAdd.js diff --git a/event/listeners/guildMemberAdd.js b/event/listeners/guildMemberAdd.js new file mode 100644 index 0000000..4c07997 --- /dev/null +++ b/event/listeners/guildMemberAdd.js @@ -0,0 +1,45 @@ +const { Listener } = require('discord-akairo'); +const reload = require('auto-reload'); +const rand = require('../../rand.js'); + +class guildMemberAddListener extends Listener { + constructor() { + super('guildMemberAdd', { + emitter: 'client', + event: 'guildMemberAdd' + }); + } + + async exec(guild) { + let welcome = reload(`../../welcome/${guild.guild.id}.json`); + + const channel = this.client.channels.get(welcome['channel']); + + let welcomeMessage = welcome['message']; + + welcomeMessage = welcomeMessage.replace(/\[member\]/, guild.user.username); + welcomeMessage = welcomeMessage.replace(/\[server\]/, guild.guild.name); + + let attach; + if (welcomeMessage.includes('[attach:')) { + attach = welcomeMessage.split(/(\[attach:.*?])/); + for (let i = 0, l = attach.length; i < l; i++) { + if (attach[i].includes('[attach:')) { + attach = attach[i].replace('[attach:', '').slice(0, -1); + i = attach.length; + } + } + welcomeMessage = welcomeMessage.replace(/(\[attach:.*?])/, ''); + } + + welcomeMessage = rand.random(welcomeMessage); + + + if (attach) { + return channel.send(welcomeMessage, {files: [attach]}); + } else { + return channel.send(welcomeMessage); + } + } +} +module.exports = guildMemberAddListener; \ No newline at end of file