discord.js

How to make an embed with all the channels and roles with mention


Im fairly new to making bots so I dont know how collections work and I need an embed that shows me all the channels and roles with mention. Its part of a !serverinfo command.


Solution

  • You can get the embed by doing this for Channels

    const channelinfo = [];
    const keys = Array.from(message.guild.channels.cache.keys())
    for(let i = 0 ; i < keys.length; i++){
       const channel  = message.guild.channels.cache.get(keys[1])
       channelinfo.push(`Channel name: ${channel.name}\nChannel mention: <#${channel.id}>`)
    }
    message.channel.send(`Channelinfo:\n` + channelinfo.join(`\n`))
    

    And same for Roles.