mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Send message on guild join/leave
This commit is contained in:
@@ -11,6 +11,7 @@ POSTER_ID=
|
|||||||
POSTER_TOKEN=
|
POSTER_TOKEN=
|
||||||
POSTER_TIME=
|
POSTER_TIME=
|
||||||
REPORT_CHANNEL_ID=
|
REPORT_CHANNEL_ID=
|
||||||
|
JOIN_LEAVE_CHANNEL_ID=
|
||||||
|
|
||||||
# Emoji IDs
|
# Emoji IDs
|
||||||
GOLD_FISH_EMOJI_ID=
|
GOLD_FISH_EMOJI_ID=
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
const { XIAO_TOKEN, OWNERS, XIAO_PREFIX, INVITE } = process.env;
|
const { XIAO_TOKEN, OWNERS, XIAO_PREFIX, INVITE } = process.env;
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const { Intents } = require('discord.js');
|
const { Intents, MessageEmbed } = require('discord.js');
|
||||||
const Client = require('./structures/Client');
|
const Client = require('./structures/Client');
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
commandPrefix: XIAO_PREFIX,
|
commandPrefix: XIAO_PREFIX,
|
||||||
@@ -115,12 +115,38 @@ client.on('message', async msg => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
client.on('guildCreate', async guild => {
|
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 {
|
try {
|
||||||
const usage = client.registry.commands.get('help').usage();
|
const usage = client.registry.commands.get('help').usage();
|
||||||
await guild.systemChannel.send(`Hi! I'm Xiao, use ${usage} to see my commands, yes?`);
|
await guild.systemChannel.send(`Hi! I'm Xiao, use ${usage} to see my commands, yes?`);
|
||||||
} catch {
|
} 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 });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ const { list } = require('../../util/Util');
|
|||||||
const reasons = ['bug', 'feedback', 'suggestion'];
|
const reasons = ['bug', 'feedback', 'suggestion'];
|
||||||
const reasonColors = ['RED', 'GREEN', 'YELLOW'];
|
const reasonColors = ['RED', 'GREEN', 'YELLOW'];
|
||||||
const displayReasons = ['🐛 Bug Report', '📬 Feedback', '❓ Suggestion'];
|
const displayReasons = ['🐛 Bug Report', '📬 Feedback', '❓ Suggestion'];
|
||||||
const { REPORT_CHANNEL_ID } = process.env;
|
|
||||||
|
|
||||||
module.exports = class ReportCommand extends Command {
|
module.exports = class ReportCommand extends Command {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
@@ -40,9 +39,9 @@ module.exports = class ReportCommand extends Command {
|
|||||||
.setFooter(`ID: ${msg.author.id}`)
|
.setFooter(`ID: ${msg.author.id}`)
|
||||||
.setTimestamp()
|
.setTimestamp()
|
||||||
.setColor(reasonColors[reason]);
|
.setColor(reasonColors[reason]);
|
||||||
if (REPORT_CHANNEL_ID) {
|
const channel = await this.client.fetchReportChannel();
|
||||||
|
if (channel) {
|
||||||
try {
|
try {
|
||||||
const channel = await this.client.channels.fetch(REPORT_CHANNEL_ID);
|
|
||||||
await channel.send({ embed });
|
await channel.send({ embed });
|
||||||
} catch {
|
} catch {
|
||||||
await this.sendOwnerDM(embed);
|
await this.sendOwnerDM(embed);
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiao",
|
"name": "xiao",
|
||||||
"version": "119.12.4",
|
"version": "119.12.5",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Xiao.js",
|
"main": "Xiao.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
+20
-1
@@ -9,7 +9,16 @@ const MemePosterClient = require('./MemePoster');
|
|||||||
const activities = require('../assets/json/activity');
|
const activities = require('../assets/json/activity');
|
||||||
const leaveMsgs = require('../assets/json/leave-messages');
|
const leaveMsgs = require('../assets/json/leave-messages');
|
||||||
const subreddits = require('../assets/json/meme');
|
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 {
|
module.exports = class XiaoClient extends CommandoClient {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
@@ -69,4 +78,14 @@ module.exports = class XiaoClient extends CommandoClient {
|
|||||||
});
|
});
|
||||||
return buf;
|
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