未显示带有嵌入式的欢迎消息

时间:2020-05-21 05:36:21

标签: javascript bots discord discord.js

因此,我制作了一个机器人,该机器人将在频道中向新成员发送欢迎消息。 我的代码应该能正常工作,因为它没有在控制台中发送任何错误,但是我的机器人没有发送欢迎消息。

我尝试了很多事情:

  • 使对象嵌入(不)

  • 制作了4个不同的长代码(全部无效)

  • 在网上搜索并观看了一些提示(控制台中没有错误,但未发送)

我正在使用discord.js@v12

代码:

client.on('guildMemberAdd', member => {
  // Finds the channel name from the array
  function channelNamesFilter(channel) {
    let channelNames = ['name', 'welcome', 'welcoming', 'greeting', 'general', 'hello'];

    if (channelNames.includes(channel.name)) {
      return true;
    }

    return false;
  }


  const welcome = new Discord.MessageEmbed()
    .setColor('#F2CC0D')
    .setTitle('Welcome To The Server!')
    .addFields({
      name: member.nickname
    }, {
      name: '\n ',
      value: 'Make sure to visit the FAQ and Rules channel (if there are)!'
    })
    .setImage(member.user.avatarURL)

  let filteredChannels = member.guild.channels.cache.filter(channelNamesFilter);
  filteredChannels.forEach(element => element.send(welcome));
});

1 个答案:

答案 0 :(得分:0)

好吧,我经过十多个小时的研究才解决了!我终于明白了!

client.on('guildMemberAdd', member =>{

  const channel = member.guild.channels.cache.find(channel => channel.name.includes('welcome'));
    if (!channel) return;

//send through channel
const welcomegreet = {
  color: 0xF2CC0D,
  title: `**WELCOME TO THE SERVER, ${member.user.tag} !!**`,
  description: `I hope you will enjoy it here! \n A place full of chaos and wonder!`,
  thumbnail: {
    url: member.user.avatarURL(),
  },
  fields:[
  {
    name: 'Need Help?',
    value: 'Please read the FAQ and Rules Channels (if there are)! \n Have Fun at the Server! CHEERS ? !',
    inline: false
  },
  {
    name: 'Join Me!',
    value: 'Do: `h.help` for entertainment and profanities!',
    inline: false
  }
 ],
 timestamp: new Date(),
};

//send through dm
const welcome = {
  color: 0xF2CC0D,
  title: `**WELCOME TO THE SERVER, ${member.user.tag} !!**`,
  description: `I hope you will enjoy it here! \n A place full of chaos and wonder!`,
  thumbnail: {
    url: member.user.avatarURL(),
  },
  timestamp: new Date(),
};
member.send({ embed: welcomegreet });
channel.send({ embed: welcome });

感谢你们尝试帮助我,尽管它离解决方案不太近。 我对此进行了测试,并且效果出色! 注意: 仅当频道中带有“ welcome”一词时,此方法才有效