mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 15:07:42 +02:00
Send message on guild join/leave
This commit is contained in:
@@ -11,6 +11,7 @@ POSTER_ID=
|
||||
POSTER_TOKEN=
|
||||
POSTER_TIME=
|
||||
REPORT_CHANNEL_ID=
|
||||
JOIN_LEAVE_CHANNEL_ID=
|
||||
|
||||
# Emoji IDs
|
||||
GOLD_FISH_EMOJI_ID=
|
||||
|
||||
@@ -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;
|
||||
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
|
||||
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 {
|
||||
// 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 });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -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
@@ -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
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user