簡體   English   中英

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

[英]Discord.js Bots // Welcome function not working

所以我試圖編寫我的機器人來在玩家加入服務器時執行不同的歡迎消息。 機器人沒有在代碼中說明任何問題,但每次有人加入時,什么也沒有發生,它只是出現在日志中。 有什么線索嗎?

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);
 });
};

您的代碼中存在一些錯誤,因此我會嘗試為您修復它們。 無論如何,這個版本肯定可以工作。

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);
 });

暫無
暫無

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

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