【问题标题】:A problem with creating a channel with Discord.JS使用 Discord.JS 创建频道的问题
【发布时间】:2020-06-18 23:04:48
【问题描述】:

UPD:感谢@Tenclea 解决了问题。问题在于频道创建功能。正确的用法是message.guild.channels.create();!

我遇到了一个关于在执行命令!w 时创建文本通道的问题。问题是,当我尝试 let USER = (message.mentions.members.first()).username; 时,它会执行 undefined 并且 message.member.send() 也无法按预期工作。

附: [关于代码的信息] 该命令不仅创建了一个新的文本频道,该频道仅供命令的执行者和提及的用户使用,而且还会向其他频道 (message.channel.send();) 发送欢迎消息,并向提及的用户发送 DM (return message.member.send();)。

这是代码。提前致谢!

else if (message.content.startsWith(`${prefix}w`)) {
  if (message.member.hasPermission('KICK_MEMBERS')) {
    let random = ["test1", "test2", "test3"];
    var channelname = random[Math.floor(Math.random() * random.length)];
    let member = message.mentions.members.first();
    let USER = (message.mentions.members.first()).username;
    const channel = bot.channels.cache.get('722892241416355940');
    (async() => {
      message.delete();
      message.guild.createChannel(`${channelname} ${USER}`, {
        type: 'text',
        parent: '550691726587723786',
        permissionOverwrites: [{
          id: message.guild.id,
          deny: ['VIEW_CHANNEL', 'SEND_MESSAGES'],
        }, {
          id: message.member.id,
          allow: ['VIEW_CHANNEL', 'SEND_MESSAGES'],
        }, {
          id: message.author.id,
          allow: ['VIEW_CHANNEL', 'SEND_MESSAGES']
        }]
      });
      message.channel.send(`:wave: we got a newcomer -  <@${message.member.id}> ! Welcome!`);
      return message.member.send({
        embed: {
          color: 1437003,
          title: ":wave:  Hello!",
          description: `Welcome to the server!`,
          footer: {
            text: "Issue !help for more instructions"
          }
        }
      })
    });
  } else {
    return message.reply(' something went wrong!')
  }

}

【问题讨论】:

    标签: javascript node.js discord.js


    【解决方案1】:

    尝试将您的成员变量替换为:

    const member = message.mentions.members.first();
    

    然后检查用户是否存在:

    if (!member) return message.reply('Could not find this member.');
    

    然后,您的整个 async 函数应该如下所示:

    (async() => {
          message.delete();
          message.guild.channels.create(`${channelname} ${member.user.username}`, {
            type: 'text',
            parent: '550691726587723786',
            permissionOverwrites: [{
              id: message.member.id,
              allow: ['VIEW_CHANNEL', 'SEND_MESSAGES'],
            }, {
              id: member.user.id,
              allow: ['VIEW_CHANNEL', 'SEND_MESSAGES']
            }]
          });
          message.channel.send(`:wave: we got a newcomer -  <@${message.member.id}> ! Welcome!`);
          return member.send({
            embed: {
              color: 1437003,
              title: ":wave:  Hello!",
              description: `Welcome to the server!`,
              footer: {
                text: "Issue !help for more instructions"
              }
            }
          })
        });
    

    希望对你有帮助:)

    【讨论】:

    • 嘿,谢谢你的提示!奇怪的是,这个解决方案不起作用。不仅如此,该命令刚刚停止执行,没有留下任何错误或日志!这是屏幕截图:ibb.co/Wkm5sbb
    • 聊天中连一条消息都没有?
    • 奇怪..你介意提供一个完整文件的链接吗?
    • 当然!在这里:pastebin.com/qc0LiDxv
    猜你喜欢
    • 2023-03-27
    • 2021-04-04
    • 2019-07-14
    • 2021-05-04
    • 1970-01-01
    • 2021-10-12
    • 2022-01-06
    • 2018-03-04
    • 2022-01-18
    相关资源
    最近更新 更多