Send message on guild join/leave

This commit is contained in:
Dragon Fire
2020-07-07 17:58:33 -04:00
parent 6b0eadb7db
commit 0ec88c47c6
5 changed files with 57 additions and 12 deletions
+1
View File
@@ -11,6 +11,7 @@ POSTER_ID=
POSTER_TOKEN=
POSTER_TIME=
REPORT_CHANNEL_ID=
JOIN_LEAVE_CHANNEL_ID=
# Emoji IDs
GOLD_FISH_EMOJI_ID=
+29 -3
View File
@@ -1,7 +1,7 @@
require('dotenv').config();
const { XIAO_TOKEN, OWNERS, XIAO_PREFIX, INVITE } = process.env;
const path = require('path');
const { Intents } = require('discord.js');
const { Intents, MessageEmbed } = require('discord.js');
const Client = require('./structures/Client');
const client = new Client({
commandPrefix: XIAO_PREFIX,
@@ -115,12 +115,38 @@ client.on('message', async msg => {
});
client.on('guildCreate', async guild => {
if (!guild.systemChannel || !guild.systemChannel.permissionsFor(client.user).has('SEND_MESSAGES')) return;
if (guild.systemChannel && guild.systemChannel.permissionsFor(client.user).has('SEND_MESSAGES')) {
try {
const usage = client.registry.commands.get('help').usage();
await guild.systemChannel.send(`Hi! I'm Xiao, use ${usage} to see my commands, yes?`);
} catch {
return; // eslint-disable-line no-useless-return
// Nothing!
}
}
const joinLeaveChannel = await client.fetchJoinLeaveChannel();
if (joinLeaveChannel) {
const embed = new MessageEmbed()
.setColor(0x7CFC00)
.setThumbnail(guild.iconURL({ format: 'png' }))
.setTitle(`Joined ${guild.name}!`)
.setFooter(`ID: ${guild.id}`)
.setTimestamp()
.addField(' Members', guild.memberCount);
await joinLeaveChannel.send({ embed });
}
});
client.on('guildDelete', async guild => {
const joinLeaveChannel = await client.fetchJoinLeaveChannel();
if (joinLeaveChannel) {
const embed = new MessageEmbed()
.setColor(0xFF0000)
.setThumbnail(guild.iconURL({ format: 'png' }))
.setTitle(`Left ${guild.name}...`)
.setFooter(`ID: ${guild.id}`)
.setTimestamp()
.addField(' Members', guild.memberCount);
await joinLeaveChannel.send({ embed });
}
});
+2 -3
View File
@@ -4,7 +4,6 @@ const { list } = require('../../util/Util');
const reasons = ['bug', 'feedback', 'suggestion'];
const reasonColors = ['RED', 'GREEN', 'YELLOW'];
const displayReasons = ['🐛 Bug Report', '📬 Feedback', '❓ Suggestion'];
const { REPORT_CHANNEL_ID } = process.env;
module.exports = class ReportCommand extends Command {
constructor(client) {
@@ -40,9 +39,9 @@ module.exports = class ReportCommand extends Command {
.setFooter(`ID: ${msg.author.id}`)
.setTimestamp()
.setColor(reasonColors[reason]);
if (REPORT_CHANNEL_ID) {
const channel = await this.client.fetchReportChannel();
if (channel) {
try {
const channel = await this.client.channels.fetch(REPORT_CHANNEL_ID);
await channel.send({ embed });
} catch {
await this.sendOwnerDM(embed);
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "119.12.4",
"version": "119.12.5",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {
+20 -1
View File
@@ -9,7 +9,16 @@ const MemePosterClient = require('./MemePoster');
const activities = require('../assets/json/activity');
const leaveMsgs = require('../assets/json/leave-messages');
const subreddits = require('../assets/json/meme');
const { XIAO_WEBHOOK_ID, XIAO_WEBHOOK_TOKEN, POSTER_ID, POSTER_TOKEN, POSTER_TIME } = process.env;
const { null, null } = require('mathjs');
const {
XIAO_WEBHOOK_ID,
XIAO_WEBHOOK_TOKEN,
POSTER_ID,
POSTER_TOKEN,
POSTER_TIME,
REPORT_CHANNEL_ID,
JOIN_LEAVE_CHANNEL_ID
} = process.env;
module.exports = class XiaoClient extends CommandoClient {
constructor(options) {
@@ -69,4 +78,14 @@ module.exports = class XiaoClient extends CommandoClient {
});
return buf;
}
fetchReportChannel() {
if (!REPORT_CHANNEL_ID) return null;
return this.channels.fetch(REPORT_CHANNEL_ID);
}
fetchJoinLeaveChannel() {
if (!JOIN_LEAVE_CHANNEL_ID) return null;
return this.channels.fetch(JOIN_LEAVE_CHANNEL_ID);
}
};