查找机器人所在的所有公会的所有渠道

时间:2020-07-13 17:32:48

标签: node.js discord.js

我想为一个命令(/ channels)编写代码,我想为该命令回复一个公会名称和该公会的所有频道(频道名称和id)

这是我的代码:

bot.on('message', msg => {
    if(msg.content === PREFIX + "channels") {
        // var roles = bot.guilds.role/*.forEach(role => console.log(role.name));*/
        // console.log(roles)
        msg.channel.send("Servers:")

        bot.guilds.forEach((guild) => {

            msg.channel.send(" - " + guild.name)

            bot.guilds.channels.array().forEach((channels) => {

                msg.channel.send('---' + channels.id + "&" + channels.name)

            })
    })}
})

1 个答案:

答案 0 :(得分:0)

client.on("message", message => {
    if (message.author.bot) return false;

    if (message.content.toLowerCase() == "/channels") {
        client.guilds.cache.forEach(guild => { // Looping through the guilds.
            const Embed = new discord.MessageEmbed();
            const Channels = guild.channels.cache.map(channel => `${channel.id} | ${channel.name}`).join(", ") // Getting the channels and mapping them by ID and NAME.
    
            Embed.setTitle(`Channels for ${guild.name}`);
            Embed.setDescription(Channels);
    
            message.channel.send(Embed); // Sending an EmbedMessage for each guild.
        });
    };
});