V
V
Victor_Lisichkin2021-04-06 19:39:35
Node.js
Victor_Lisichkin, 2021-04-06 19:39:35

How to make the bot display the channel name?

I want to make a chat logger bot. So far, I've implemented sending a message when a pin is updated in a channel. But there is one thing... The bot sends a message with the channel ID when I need it to unsubscribe its name.

const Discord = require("discord.js");
const client = new Discord.Client();
const logger = require("discordjs-logger");
logger.all(client);
const {MessageEmbed} = require('discord.js');
client.on("channelPinsUpdate", function (channel, time) {
  let logchannel = client.channels.cache.get("829024037397200926");
  let PinsUpdateEmbed = new MessageEmbed()
  .setTitle("Обновление закрепленных сообщений")
  .setColor("#FFFF00")
  .setDescription('Обновлен закреп в канале\n' + channel + '\nв ' + time)
  logchannel.send(PinsUpdateEmbed)
});
client.login("");

Just the same channel also issues ID. I want to make a variable displaying the channel name. But I don't know how to do it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lukramancer, 2021-04-06
@Victor_Lisichkin

When this event fires , the transmitted channel can be a DMChannel (private messages) or a TextChannel (a text channel on the server). In the first case, you can't get the channel name because these are private messages. In the second case, you need to get the name field ( channel.name ).
You will get something like:

.setDescription('Обновлен закреп в канале\n' + channel.name + '\nв ' + time)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question