0

How to check if a user is writing a message in a shared channel and tell him to write in a bot-specific channel?

This is the code I tried:

if (message.channel.id === "bot-playground"){
    // write code here
}else {
    message.channel.send("Write commands in #bot-playground.").then(msg => {
        timeout(3000, msg);
    });
}
סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68

3 Answers3

0
    if (message.channel.id === "bot-playground"){

This needs a channel ID, not a name. To get the ID of the channel, right-click it and select copy ID then use this. if you don't have the copy ID button you may need to Enable developer mode

Also, your mention may not work

message.channel.send("Write commands in #bot-playground.")

See

this question for more

mmoomocow
  • 1,173
  • 7
  • 27
0

Your issue is caused by the first line if (message.channel.id === "bot-playground") you are trying to use the channel name as an ID.

You either need to look it up using the ID of the channel, which you can get by enabling Developer Mode

Or, you could just use the channel name to find it like so:

message.guilds.channels.cache.find(channel => channel.name === 'bots-playground')

Syntle
  • 5,168
  • 3
  • 13
  • 34
0

Replace client with whatever variable or constant used to assign the Discord#Client object.

client.on("typingStart", (channel, user) => {

     const bot_channel = channel.guild.channels.cache.find(chan => chan.name == "bot-playground");

     if (channel.id != bot_channel.id) {
          return message.channel.send(`Write commands in <#${bot_channel.id}>`);
     }

});
Spimy
  • 340
  • 2
  • 11