临时语音通道

时间:2020-02-01 12:51:21

标签: javascript node.js discord.js

它可以工作,但事实是它消除了创建临时频道所需加入的频道。我该如何解决? 当输入“临时通道”时,该代码将创建一个临时通道。一旦输入,机器人将在您的用户名中更改频道的名称,但也会删除您需要加入以创建其他临时频道的频道。所以这不是一件好事

const usersInVoiceChannel = [];
client.on('voiceStateUpdate', async(oldmember, newmember) => {
  const config = await yml('./config.yml');
  if (config.Temp_Channels_Enabled !== "true") return;
  if (!oldmember.voiceChannel && newmember.voiceChannel) {
    usersInVoiceChannel.push({
      user: newmember.id,
      joinedAt: Date.now()
    });
  } else if (oldmember.voiceChannel && newmember.voiceChannel && oldmember.voiceChannelID !== newmember.voiceChannelID && usersInVoiceChannel.map(u => u.user).includes(oldmember.id)) {
    usersInVoiceChannel.splice(usersInVoiceChannel.indexOf(usersInVoiceChannel.find(u => u.user == oldmember.id)), 1);
    usersInVoiceChannel.push({
      user: newmember.id,
      joinedAt: Date.now()
    });
  } else if (oldmember.voiceChannel && !newmember.voiceChannel && usersInVoiceChannel.map(u => u.user).includes(oldmember.id)) {
    usersInVoiceChannel.splice(usersInVoiceChannel.indexOf(usersInVoiceChannel.find(u => u.user == oldmember.id)), 1);
  }
  let tempVoiceChannel = oldmember.guild.channels.find(c => c.type == 'voice' && c.name.toLowerCase() == config.Join_To_Create.toLowerCase());
  let tempVoiceCategory = oldmember.guild.channels.find(c => c.type == 'category' && c.name.toLowerCase() == config.Temp_Channel_Category.toLowerCase());
  if (tempVoiceChannel) {
    if (newmember.voiceChannelID == tempVoiceChannel.id) {
      oldmember.guild.createChannel(oldmember.user.username, {
        type: 'voice'
      }).then(channel => {
        channel.setParent(tempVoiceCategory);
        oldmember.setVoiceChannel(channel.id);
      })
    }
  }
  if (oldmember.voiceChannel && oldmember.voiceChannel !== newmember.voiceChannel && oldmember.voiceChannel.parentID == tempVoiceCategory.id) {
    if (oldmember.voiceChannel.members.size == 0) oldmember.voiceChannel.delete();
  }
})

0 个答案:

没有答案