Search code examples
node.jsdiscorddiscord.js

fetching current channels disocrd.js-selfbot


I'm using discord.js-selfbot-v13 and I've ran into a problem, the bot takes a list of channels that it needs to send a message to if X condition is true, however if the user gets banned from the guild it will throw an error saying message access.

Is there any way I can make it fetch the current available channels instead of the cached ones? when the user is banned the cached channels remain there for some reason so is it possible to re-fetch the cache to the latest version each time the loop happens?

I tried using client.channels.cache.fetch(id) and client.channels.cache.get(id), both producing the same error of finding non-existent channels.

Here's the current code I'm working with:

client.on("messageCreate", async (message) => {
    if(watchlist.includes(message.channel.id)){
      let link = await filterLink(message.content)
      if(link != null){
         let updated = await updateLink(link)
         if(updated){
            sendList.forEach( async (id) => {
               try{
                  
               }catch(error){console.log(error)}
            })
         }
      }
    }
})

Solution

  • I've figured a way or a workaround which might be helpful for anyone having the same issue, which is to split the bot into two bots, one watches and then sends the data over to the other one using an express server here's the code for it

    The first selfbot:

    // update function
    async function updateLink(link, channel) {
      if (link != null) {
        let target = getTarget(channel.id)
        if (target == null) {
          return false
        }
        let response = await axios.post(
          "handler link",
          {},
          {
            headers: {
              target: target,
              gamelink: link
            }
          }
        )
        if (response.statusCode == 200) {
          return true
        } else {
          return false
        }
      }
    }
    
    // message event
    client.on("messageCreate", async (message) => {
      if (watchlist.includes(message.channel.id)) {
        let link = await filterLink(message.content)
        if (link != null) {
          let updated = await updateLink(link, message.channel)
          if (updated) {
            console.log('\n['.cyan, '!'.brightMagenta, ']'.cyan, `Link successfully Updated!`.brightGreen)
          }
        }
      }
    })
    

    The server & handler:

    router.post('/', async (req, res) => {
      let Link = req.headers.gamelink
      let linksCopy = links
      linksCopy[req.headers.target] = Link
      links = linksCopy
      res.sendStatus(200)
      console.log('\n['.cyan, '!'.brightMagenta, ']'.cyan, `Starting message sending...`.brightGreen)
      client.on('ready', async () => {
        console.log('\n['.cyan, '!'.brightMagenta, ']'.cyan, `Successfully logged in!`.brightGreen)
      })
      client.login("token")
      sendList.forEach( async (id) => {
        try {
          const channel = client.channels.cache.get(id)
          let lin = verifylinks(req.headers.target)
          if (channel) {
            channel.send(lin+"\n*Received from the selfbot!*")
          }
        } catch(error) {
          console.log(error)
        }
      }) 
    })
    
    module.exports = router;
    

    I hope this will be of help for anyone running with a similar issue!