簡體   English   中英

TypeError: member is not a function when using `${member}`

[英]TypeError: member is not a function when using `${member}`

我有一個 function 在用戶加入時在 Discord 上發送隨機選擇的歡迎消息,並為其添加角色並且它曾經可以工作,但是在更新到 Z4B7D45BF672279F0CF0911EA9E94F37 后,我得到了錯誤

  • Welcome ${member}, that will be 6,99 $. Wanna pay cash or credit card? ^

類型錯誤:成員不是函數*

當用戶加入時。 有人可以幫我嗎? 這是我的代碼。

// When a member joins, this function executes.
bot.on('guildMemberAdd', (member) => {
    console.log('User ' + member.id + ' has joined the guild.');
    // Welcome messages possible options.
    let welcomeMessages = [`${member}, welcome to our server :wave:!\n\nNow you're **one of us** :new_moon_with_face:! \n\n`, 
    `Welcome, ${member}. Hope you enjoy your stay.`, `Look who showed up... ${member}`, `Welcome ${member}, have a pleasant time.`, 
    `So... ${member} just arrived.`, `Great... ${member} is here!`, `Everyone stand up! ${member} is here.`, `Hello daddy ${member}...`
    `Welcome ${member}, that will be 6,99 $. Wanna pay cash or credit card?`
    ];

    let welcomeChannel = member.guild.channels.cache.get(serverData.welcomeChannelId);
    let defaultRole = member.guild.roles.cache.get(serverData.defaultRoleId);
  
    // Both the welcome message and GIFs will be chosen randomly.
    let welcomeGif = welcomeGifs[Math.floor(Math.random() * welcomeGifs.length)];
    let welcomeMessage = welcomeMessages[Math.floor(Math.random() * welcomeMessages.length)];
  
    // This is the variable that stores the user profile picture for later use.
    let newUserIcon = member.user.displayAvatarURL;
  
    welcomeChannel.send(`${member}`);
  
    // This is my embedded message, which allows loads of customization.
    let welcomeMessageEmbed = new Discord.MessageEmbed()
      .setColor(Math.floor(Math.random() * 16777214) + 1) // The color will be random.
      .setDescription(welcomeMessage) // A message will be chosen randomly from the welcome messages tab.
      .setImage(welcomeGif) // Same with the GIF.
      .setThumbnail(newUserIcon) // The icon of the embedded message will be the user profile picture.
  
    // Send in the embed.
    welcomeChannel.send(welcomeMessageEmbed);
  
    // This is the default role.
    member.roles.add(defaultRole);
});

member是 object 並且您需要一個字符串。 嘗試在模板文字中使用member.displayName

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM