在Discord上的特定频道中发送消息

时间:2020-03-25 14:35:00

标签: javascript bots discord.js

我已经阅读了其他多个线程,其他每个线程都说要使用client.channels.get(id).send(msg)或client.channels.find(id).send(msg)。但是,无论何时使用其中任何一个,都会弹出此错误消息:

TypeError:client.channels.get不是函数

在ClientRequest。 (C:\ Users \ Sean \ Desktop \ Crow Bot \ index.js:19:25)

在Object.onceWrapper(events.js:418:26)

在ClientRequest.emit(events.js:311:20)

在HTTPParser.parserOnIncomingClient [如onIncoming](_http_client.js:603:27)

在HTTPParser.parserOnHeadersComplete(_http_common.js:119:17)

在TLSSocket.socketOnData(_http_client.js:476:22)

在TLSSocket.emit(events.js:311:20)

在addChunk(_stream_visible.js:294:12)

在可读AddChunk(_stream_visible.js:275:11)

在TLSSocket.Readable.push(_stream_visible.js:209:10)

我的代码

const Discord = require('discord.js')
const client = new Discord.Client()
const fullUrl = 'https://jaiminisbox.com/reader/read/solo-leveling/en/0/'
var chapter = 1
const https = require('https')

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`)
  UrlExists(fullUrl);
})

function UrlExists(url) {
  //Infinite loop
    url = fullUrl
    url += chapter
    https.get(url, res => {
      if (res.statusCode != 404) {
        console.log('Chapter ' + chapter + ' exists')
        chapter += 1
        client.channels.get("id").send("Chapter exists")
      }
    })
    //Pause code to check every 5 minutes
}

任何其他提示或建议也将不胜感激

编辑:

该机器人的目的是检查网站,看漫画的下一章是否已经发布。如果它导致404,则什么也不会发生,但是如果没有,则它将在Discord上的特定频道中发布新章节,然后将更新正在检查的章节

1 个答案:

答案 0 :(得分:0)

尝试使用

client.channels.cache.get("id").send("Chapter Exists")

您可能还想参考 the documentation

this也可能对您有用