Add custom welcome messages with mention
This commit is contained in:
25
bot.js
25
bot.js
@@ -3,6 +3,7 @@ import JsonManager from "./wwwroot/core/utils/jsonManager.js";
|
||||
import {Logger} from "./wwwroot/core/logging/logger.js";
|
||||
import {launchWorker} from "./wwwroot/core/namecards/workerLauncher.js";
|
||||
import {AttachmentBuilder} from "discord.js";
|
||||
import StringFormatter from "./wwwroot/core/utils/stringFormatter.js";
|
||||
|
||||
const launch = async () => {
|
||||
try{
|
||||
@@ -32,6 +33,17 @@ const launch = async () => {
|
||||
});
|
||||
|
||||
data.client.on('guildMemberAdd', async (member) => {
|
||||
const possibleMessages = [
|
||||
"<@:user> is one of us!",
|
||||
"I know what you are, <@:user>...",
|
||||
"Osmanthus wine tastes the same as I— oop, wrong line <@:user>",
|
||||
"Yeah yeah, welcome or whatever <@:user>",
|
||||
"OH. MY. GOD Y'ALL— <@:user> is here!",
|
||||
"So... we're all seeing <@:user, right?>",
|
||||
"<@:user> is right behind me, aren't they...?"
|
||||
]
|
||||
const choseMessage = possibleMessages[Math.floor(Math.random() * possibleMessages.length)];
|
||||
|
||||
try {
|
||||
const avatarUrl = member.user.displayAvatarURL({ extension: 'png', size: 512 });
|
||||
const username = member.displayName || member.user.username;
|
||||
@@ -43,19 +55,22 @@ const launch = async () => {
|
||||
});
|
||||
|
||||
const attachment = new AttachmentBuilder(Buffer.from(result.result), { name: 'namecard.png' });
|
||||
/*const attachment = new AttachmentBuilder(
|
||||
Buffer.isBuffer(result.result) ? result.result : Buffer.from(result.result),
|
||||
{ name: 'namecard.png' }
|
||||
);*/
|
||||
|
||||
const channel = await member.guild.channels.fetch(data.welcomeChannelID);
|
||||
await channel.send({ files: [attachment] });
|
||||
await channel.send({
|
||||
content: StringFormatter.format(choseMessage, [ {key : "user", value : member.id} ]),
|
||||
allowedMentions: {
|
||||
users: [member.id]
|
||||
},
|
||||
files: [attachment]
|
||||
});
|
||||
|
||||
} catch (err) {
|
||||
await Logger.error('Failed to generate/send name card:', err);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
process.on('SIGINT', async () => {
|
||||
try {
|
||||
await data.sender.send(data.updateChannelID, "I'm shutting down, now. Bye! 👋")
|
||||
|
||||
@@ -2,6 +2,7 @@ import {data} from "../wwwroot/core/appData.js";
|
||||
import {launchWorker} from "../wwwroot/core/namecards/workerLauncher.js";
|
||||
import {AttachmentBuilder} from "discord.js";
|
||||
import {Logger} from "../wwwroot/core/logging/logger.js";
|
||||
import StringFormatter from "../wwwroot/core/utils/stringFormatter.js";
|
||||
|
||||
data.client.on('clientReady', async () => {
|
||||
console.log("Ready!");
|
||||
@@ -14,6 +15,17 @@ data.client.on('clientReady', async () => {
|
||||
});
|
||||
|
||||
data.client.on('guildMemberAdd', async (member) => {
|
||||
const possibleMessages = [
|
||||
"<@:user> is one of us!",
|
||||
"I know what you are, <@:user>...",
|
||||
"Osmanthus wine tastes the same as I— oop, wrong line <@:user>",
|
||||
"Yeah yeah, welcome or whatever <@:user>",
|
||||
"OH. MY. GOD Y'ALL— <@:user> is here!",
|
||||
"So... we're all seeing <@:user, right?>",
|
||||
"<@:user> is right behind me, aren't they...?"
|
||||
]
|
||||
const choseMessage = possibleMessages[Math.floor(Math.random() * possibleMessages.length)];
|
||||
|
||||
try {
|
||||
const avatarUrl = member.user.displayAvatarURL({ extension: 'png', size: 512 });
|
||||
const username = member.displayName || member.user.username;
|
||||
@@ -25,13 +37,15 @@ data.client.on('guildMemberAdd', async (member) => {
|
||||
});
|
||||
|
||||
const attachment = new AttachmentBuilder(Buffer.from(result.result), { name: 'namecard.png' });
|
||||
/*const attachment = new AttachmentBuilder(
|
||||
Buffer.isBuffer(result.result) ? result.result : Buffer.from(result.result),
|
||||
{ name: 'namecard.png' }
|
||||
);*/
|
||||
|
||||
const channel = await member.guild.channels.fetch(data.welcomeChannelID);
|
||||
await channel.send({ files: [attachment] });
|
||||
await channel.send({
|
||||
content: StringFormatter.format(choseMessage, [ {key : "user", value : member.id} ]),
|
||||
allowedMentions: {
|
||||
users: [member.id]
|
||||
},
|
||||
files: [attachment]
|
||||
});
|
||||
|
||||
} catch (err) {
|
||||
await Logger.error('Failed to generate/send name card:', err);
|
||||
|
||||
Reference in New Issue
Block a user