Discord.js Bots //欢迎功能不起作用

时间:2020-10-20 17:07:36

标签: javascript node.js discord discord.js

因此,如果玩家加入服务器,我试图对我的机器人进行编码以执行不同的欢迎消息。该漫游器未在代码中说明任何问题,但每次有人加入时,都不会发生任何事情,它只会出现在日志中。有任何线索吗?

module.exports = (client) => {
 const channelId = '766761508427530250'; // welcome channel

 client.on('guildMemberAdd', (member) => {
  console.log(member);

  const welcomes = [
   `The member <@${member.id}> is joining us, welcome to ${member.guild}!`,
   `Say hello to <@${member.id}> Welcome to ${member.guild}!`,
   `Cheers, ${member}, welcome to the server!`,
   `I am smelling newcomers! Welcome, ${member} to ${member.guild}!`,
  ];

  const message = `${
   welcomes[Math.floor(Math.random() * welcomes.length)]
  } Please read the ${member.guild.channels.cache.get(
   '766731745960919052'
  )} and click on verify to gain full access to the server.`;

  const channel = member.guild.channels.cache.get(channelId);
  channel.send(message);
 });
};

1 个答案:

答案 0 :(得分:0)

您的代码中存在一些错误,因此我将尝试为您修复它们。这个版本肯定应该可以使用。

client.on('guildMemberAdd', member => {
  console.log(member);

  const welcomes = [
   `The member ${member} is joining us, welcome to ${member.guild}!`,
   `Say hello to ${member.id} Welcome to ${member.guild}!`,
   `Cheers, ${member}, welcome to the server!`,
   `I am smelling newcomers! Welcome, ${member} to ${member.guild}!`
  ];

  const message = `${welcomes[~~(Math.random() * welcomes.length)]} Please read the <#766731745960919052> and click on verify to gain full access to the server.`;

  const channelId = '766761508427530250'; // welcome channel
  const channel = member.guild.channels.cache.find(chan => chan.id === `${channelId}`);
  channel.send(message);
 });