An advance welcoming snippet which will look into the username and if the username contains a badword the user will be banned, it will update the joined users data to google sheet, it can also do auto role by separating bots and users - iamhv!
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const jimp = require('jimp');
const bot = await lib.discord.guilds['@0.1.0'].members.retrieve({
user_id: context.params.event.user.id,
guild_id: context.params.event.guild_id,
});
const avatarBorderColor = 0xffdb00ff;
const channelID = `896373092648103966`; //your welcome channel id
const bannerURL =
'https://cdn.discordapp.com/attachments/896377837211222046/944518217840345088/ElationLogo.png';
const avatarURL = `https://cdn.discordapp.com/avatars/${context.params.event.user.id}/${context.params.event.user.avatar}.png?size=128`;
let img = await jimp.read(bannerURL);
let avatar = await jimp.read(
'https://polybit-apps.s3.amazonaws.com/stdlib/users/discord/profile/image.png?1621007833204'
);
let timeZone = 'Asia/Kolkata';
let timeString = new Date().toLocaleString('en-US', {
timeZone: timeZone
});
let role = ``; // Put the ID of your member role here!
let botrole = ``; //put the role id your bots role
let nick = context.params.event.user.username;
let badword = [ 'badword1', 'badword2' ];
if (nick.includes(`${badword}`)) {
let result = await lib.discord.guilds['@0.1.0'].bans.create({
user_id: `${context.params.event.user.id}`,
guild_id: `${context.params.event.guild_id}`,
reason: `in appropriate username`,
});
} else {
if (context.params.event.user.avatar) {
try {
avatar = await jimp.read(avatarURL);
} catch (e) {
console.log(
`Could not read the URL passed to JIMP. Make sure you're not using test data!`
);
}
}
let avatarRing = await new jimp(256 + 32, 256 + 32, avatarBorderColor); //imagine size and editing starts here touch it if you know what to do
avatarRing.circle();
img.resize(2569, 2560);
avatar.circle();
avatar.resize(556, 556);
img.composite(avatar, 1012 - 8, 1828);
await jimp.loadFont(jimp.FONT_SANS_128_WHITE).then((font) => {
img.print(
font,
700,
250, //440
{
text: `${context.params.event.nick || context.params.event.user.username}#${context.params.event.user.discriminator}`,
alignmentX: jimp.HORIZONTAL_ALIGN_CENTER,
alignmentY: jimp.VERTICAL_ALIGN_MIDDLE,
},
1224,
400
);
});
let user = await lib.discord.users['@0.1.3'].retrieve({
user_id: context.params.event.user.id,
});
let avatarBuffer = await lib.http.request['@1.1.5']({
method: 'GET',
url: avatarURL,
});
let result = await lib.discord.webhooks['@0.0.0'].create({
channel_id: channelID,
name: `${context.params.event.user.username}`,
avatar: avatarBuffer.body,
});
let buffer = await img.getBufferAsync(jimp.MIME_PNG);
await lib.discord.webhooks['@0.0.0'].execute({
webhook_id: `${result.id}`,
webhook_token: `${result.token}`,
channel_id: channelID,
content: `<@!${context.params.event.user.id}>`,
filename: 'welcome.png',
file: buffer,
tts: false,
embeds: [
{
type: 'rich',
title: `Welcome`,
description: `welcome to our server make sure you have yourself a great time`,
color: 0x00ffff,
thumbnail: {
url: `https://cdn.discordapp.com/avatars/896634435292778517/63e0b9bed49d480a7348eb6f5f982d70?size=1024`, //{avatar}
height: 0,
width: 0,
},
},
],
});
/* await lib.googlesheets.query['@0.3.0'].insert({
range: `A:D`,
fieldsets: [
{
Day: `${timeString}`,
Username: `${context.params.event.user.username}`,
ID: `${context.params.event.user.id}`,
},
],
});*/ //enable this if you want the google sheet function
if (bot.user.bot == true) {
await lib.discord.guilds['@0.1.0'].members.roles.update({
role_id: `${botrole}`,
user_id: `${context.params.event.user.id}`,
guild_id: `${context.params.event.guild_id}`,
});
} else {
await lib.discord.guilds['@0.1.0'].members.roles.update({
role_id: `${role}`,
user_id: `${context.params.event.user.id}`,
guild_id: `${context.params.event.guild_id}`,
});
}
await new Promise((resolve) => setTimeout(resolve, 5000));
await lib.discord.webhooks['@0.0.0'].destroy({
webhook_id: `${result.id}`,
});
}
//make sure you set the timeout to 3000ms
//built by iamhv#1180
//your gsheet should looks like this
//https://cdn.discordapp.com/attachments/902954913116590090/983764000800112670/unknown.png