有没有办法获取频道名称?

Is there a way to get a channel name?

有没有办法获取频道名称?我正在创建一个机器人来记录创建和删除的频道,我希望能够获取频道名称而不是 ID。

我检查了documentation,没有名字属性,所以我想知道是否有办法解决这个问题。

我目前的代码是这样的:

const Discord = require('discord.js');
const client = new Discord.Client();

client.on('channelCreate', channel => {
    const logChannel = channel.guild.channels.find(ch => ch.name === 'log');
    if (!logChannel) return;
    const embed = new Discord.RichEmbed()
        .setColor('#64cd6d')
        .setAuthor('Channel created')
        .setTitle('I want to put the channel name here');
        .setDescription(channel)
        .setFooter(`ID: ${channel.id}`)
        .setTimestamp();
    logChannel.send(embed);
})

如果是 guildChannel,您可以简单地使用 channel.name。 对于您的 channelDelete 事件,它也像这样工作。

您检查的是 Discord 上的所有 个频道。所以这意味着任何文本通道(直接消息或 Discord 服务器),你只受属性和方法的限制。