I don’t know where the recursion is happening. I don’t know how to stop it from sending multiple welcome attachments. After a while my bot crashes and sends the error: RequestAbortedError [AbortError]: Request aborted. I use sequelize as my schema / model.
my code:
const { WelcomeLeave } = require('canvafy');
const Guild = require('../model/guild');
function getRandomColor() {
const letters = '0123456789ABCDEF';
let color = '#';
for (let i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
module.exports = {
name: 'guildMemberAdd',
async execute(member) {
const WelcomeGuild = await Guild.findOne({ where: {id: member.guild.id } });
const randomBorderColor = getRandomColor();
const randomAvatarBorderColor = getRandomColor();
const welcome = await new WelcomeLeave()
.setAvatar(member.user.displayAvatarURL({ forceStatic: true, extension: 'png' }))
.setBackground('image', WelcomeGuild.welcomeBackground || '')
.setTitle('Welcome!')
.setDescription(`Glad you're here ${member.user.username}!`)
.setBorder(randomBorderColor)
.setAvatarBorder(randomAvatarBorderColor)
.setOverlayOpacity(0.3)
.build();
if(WelcomeGuild.welcomeChannelId) {
const welcomeChannel = await member.guild.channels.fetch(WelcomeGuild.welcomeChannelId);
welcomeChannel.send({ content: `Hello ${member}!`, files: [{ attachment: welcome, name: `welcome-${member.id}.png` }] });
}
if(WelcomeGuild.welcomeRoleId) {
const welcomeRole = await member.guild.roles.fetch(WelcomeGuild.welcomeRoleId);
await member.roles.add(welcomeRole);
}
}
}
I don’t know how to properly pass the value of the image string like these;
if(WelcomeGuild.welcomeChannelId) {
const welcomeChannel = await member.guild.channels.fetch(WelcomeGuild.welcomeChannelId);
if(WelcomeGuild.welcomeRoleId) {
const welcomeRole = await member.guild.roles.fetch(WelcomeGuild.welcomeRoleId);
and implement it to the background
if(WelcomeGuild.welcomeBackground) {
const welcomeBackground = WelcomeGuild.welcomeBackground;
^this doesn’t work
New contributor
Nico Nico is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.