Discord bot重复欢迎消息

时间:2020-07-16 11:58:16

标签: javascript discord discord.js

我正在创建一个不和谐的机器人,当我放置一些代码时,该机器人会多次执行它。例如,我将此欢迎代码发送给新用户,并且该机器人将欢迎照片发送了4次。 代码:

bot.on('guildMemberAdd', async member => {
    
    let wChan = "Channel_ID"
    
    if(wChan == null) return;
    
    if(!wChan) return;
    
let font = await jimp.loadFont(jimp.FONT_SANS_64_BLACK) //We declare a 32px font
  let font64 = await jimp.loadFont(jimp.FONT_SANS_64_WHITE)//We declare a 64px font
  let font64b = await jimp.loadFont(jimp.FONT_SANS_64_WHITE)
  let bfont64 = await jimp.loadFont(jimp.FONT_SANS_64_BLACK)
  let mask = await jimp.read('https://i.imgur.com/552kzaW.png') //We load a mask for the avatar, so we can make it a circle instead of a shape
  let welcome = await jimp.read('http://rovettidesign.com/wp-content/uploads/2011/07/clouds2.jpg') //We load the base image
  jimp.read(member.user.displayAvatarURL).then(avatar => { //We take the user's avatar
    avatar.resize(200, 200) //Resize it
    mask.resize(200, 200) //Resize the mask
    avatar.mask(mask) //Make the avatar circle
    welcome.resize(1000, 300)
    
  welcome.print(font64, 265, 35, `Bienvenido ${member.user.username} a`) //We print the new user's name with the 64px font
  welcome.print(bfont64, 265, 105, ` ${member.guild.name}`)
  welcome.print(font64, 265, 175, `Gracias a ti ya somos `)
  welcome.print(font64b, 265, 230, `${member.guild.memberCount} usuarios`)
  welcome.composite(avatar, 40, 45).write('Welcome2.png') //Put the avatar on the image and create the Welcome2.png bot
    try{
  member.guild.channels.get(wChan).send(``, { files: ["Welcome2.png"] }) //Send the image to the channel
  }catch(e){
      // dont do anything if error occurs
      // if this occurs bot probably can't send images or messages
  }
  })
});

它给我的错误是:

(node:7963) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 6 guildMemberAdd listeners added. Use emitter.setMaxListeners() to increase limit

我已经在代码中添加了一些process.setMaxListeners (1);,但是它不起作用

0 个答案:

没有答案