提问者:小点点

有没有一种方法,我可以列出频道在一个不和谐的服务器


我使用的是discord.jsv12,我需要的是这样的;

1=welcome_channel

2=一般聊天等。

另外,我正在使用下面的代码

const listedChannels = []
    message.guild.channels.cache.forEach(channel => {
      listedChannels.push(channel.name)
    })
    const channelembed = new Discord.MessageEmbed()
    .setTitle("Channel list ")
    .setDescription(listedChannels)
    .setTimestamp()
    .setColor("RANDOM")
    .setFooter("Write the number of the channel")
    message.channel.send(channelembed)

共3个答案

匿名用户

您可以通过简单地按名称映射channels.cache集合来实现这一点。

(筛选是因为类别也被计算为通道。)

message.guild.channels.cache.filter(channel => channel.type == "text" || channel.type == "voice").map(channel => channel.name).join(", ");

匿名用户

@Sintuz(&P;@jakye我把它们结合起来,修改了一些代码,然后我做了这个:

const description = []
let i = 1
message.guild.channels.cache.forEach(channel => {
  if (channel.type == "text") {
  description.push(i + "=" +channel.name + "\n")
    i++
  } else return;
})
const channelembed = new Discord.MessageEmbed()
.setTitle("Write the number of the channel")
.setDescription(description)
.setTimestamp()
.setColor("RANDOM")
.setFooter("Write the number of the channel");
message.channel.send(channelembed)

而且成功了!

匿名用户

您可以使用:

const channels = [] // create starting array

message.guild.channels.cache // get all channels
  .filter((channel) => channel.type !== "category") // filter out the categories (they are also counted as channels)
  .forEach((channel) => channels.push(channel.name)); // add each channel name to the array

const channelembed = new Discord.MessageEmbed() // make the embed
  .setTitle("Channel List")
  .setDescription(channels.map((channel, index) => `${index + 1} - ${channel}`).join('\n')) // map the channel names to preferred format
  .setTimestamp()
  .setColor("RANDOM")
  .setFooter("Write the number of the channel");

channels的输出示例:

1 - general
2 - media
3 - bot-spam
4 - announcements