semih gök
semih gök

Reputation: 3

Discord js getting a bot's message

Well i need to do this: on a channel a bot announces "btc" price (not real) im trying to get the price and send the price to a specificed channel My code

sa.on("message", (message) => {
  if (message.content.startsWith("🟠")) {
    if (message.author.id == "974187708933083157") {
      client.channels.get('955536998989447249').send(`${message.content}`);

    
    } else message.channel.send(``);
  }
})

So if a message that starts with 🟠 the bot needs to get the price and send it to the channel (955536998989447249) But it not working my bot is working fine but not getting price and sendimg it

Upvotes: 0

Views: 152

Answers (1)

ignis
ignis

Reputation: 442

Firstly don't try sending empty message message.channel.send(``);, it will just throw an error.

The main problem, is that client.channels (ChannelManager) doesn't have a "get" method.

Assuming you are using djs v13, to get a channel, you can get it from cache with:

client.channels.cache.get('955536998989447249').send("sth")

however this might not always work if the channel is not currently cached. Other option is to fetch it, though it is an asynchronous operation, so it looks a bit different:

client.channels.fetch('955536998989447249').then(channel => channel.send("sth"))

Upvotes: 1

Related Questions