How can I convert a channel/server ID to its name?

I’m trying to create a more detailed console log for my discord bot, and I wanted to log all of the messages that the bot can see. I did this so far:

client.on('message', message => {

    const User = client.users.cache.get(message.author.id); // Getting the user by ID.
    const Channel = client.channels.cache.get(message.channel.id); //getting the channel ID
    console.log(User.tag + " in " + message.channel + " of " + message.guild + " said: " + message.content);

//all of my other code

});

client.login(token);

I was able to figure out how to convert the user ID into a username, but I couldn’t do the same for channel IDs and Server IDs. I tried a similar approach with the channel ID by using the same code for the username for the channel, but it still gives me the numbers. In the console, this is what appears.
Kingamezz#0218 in 763786268181397527 of 763786268181397524 said: message text

My goal is to try and convert the IDs to the correct names, so I get a result that looks like
Kingamezz#0218 in #general of Testing Server said: message text

77 thoughts on “How can I convert a channel/server ID to its name?”

Leave a Comment