SpikeHD / AmazonMonitor

Amazon price checker, item monitor and stock monitor, all shoved into a Discord bot
GNU General Public License v3.0
234 stars 39 forks source link

[ERROR]: DiscordAPIError while attempting to watch a category #75

Closed rajagrawal1 closed 3 years ago

rajagrawal1 commented 3 years ago

Describe the issue:

I receive a DiscoardAPIError when trying to watch a category.

Paste the contents of your config.json, excluding the token, here:

{
  "prefix":"!",
  "token":"removed-for-privacy",
  "minutes_per_check":2,
  "search_response_ms": 30000,
  "url_params":{
    "s":"price-asc-rank"
  },
  "guild_item_limit":5,
  "cache_limit": 10,
  "required_perms":["permission_1", "permission_2"],
  "tld":"in",
  "auto_cart_link":true,
  "debug_enabled":true
}

Provide console output with debug mode enabled:

  ##########################################################################
   _____                                        __      __         __         .__
  /  _  \   _____ _____  ____________   ____   /  \    /  \_____ _/  |_  ____ |  |__   ___________
 /  /_\  \ /     \\__  \ \___   /  _ \ /    \  \   \/\/   /\__  \\   __\/ ___\|  |  \_/ __ \_  __ \
/    |    \  Y Y  \/ __ \_/    (  <_> )   |  \  \        /  / __ \|  | \  \___|   Y  \  ___/|  | \/
\____|__  /__|_|  (____  /_____ \____/|___|  /   \__/\  /  (____  /__|  \___  >___|  /\___  >__|
        \/      \/     \/      \/          \/         \/        \/          \/     \/     \/

  by SpikeHD#3336
  ##########################################################################

[MESSAGE]  Loading command: details.js
[MESSAGE]  Loading command: help.js
[MESSAGE]  Loading command: search.js
[MESSAGE]  Loading command: unwatch.js
[MESSAGE]  Loading command: watch.js
[MESSAGE]  Loading command: watchlist.js
[DEBUG]  Data storage type: json
[MESSAGE]  Watchlist Loaded
[MESSAGE]  Puppeteer Launched
[DEBUG]  []
[DEBUG]  {
  link: '',
  category: 'https://www.amazon.in/b/?_encoding=UTF8&node=1389401031',
  query: '',
  priceLimit: 0
}
[DEBUG]  Price Limit: 0
[WARNING]  TypeError: Cannot read properties of undefined (reading 'includes')
    at Object.exports.categoryDetails (C:\Users\rajsa\Documents\Git Repos\AmazonMonitor\common\Amazon.js:61:12)
    at Object.module.exports.run (C:\Users\rajsa\Documents\Git Repos\AmazonMonitor\commands\watch.js:76:32)
    at exec (C:\Users\rajsa\Documents\Git Repos\AmazonMonitor\index.js:75:13)
    at Client.<anonymous> (C:\Users\rajsa\Documents\Git Repos\AmazonMonitor\index.js:67:61)
    at Client.emit (node:events:390:28)
    at Client.emit (node:domain:475:12)
    at MessageCreateAction.handle (C:\Users\rajsa\Documents\Git Repos\AmazonMonitor\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
    at Object.module.exports [as MESSAGE_CREATE] (C:\Users\rajsa\Documents\Git Repos\AmazonMonitor\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (C:\Users\rajsa\Documents\Git Repos\AmazonMonitor\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
    at WebSocketShard.onPacket (C:\Users\rajsa\Documents\Git Repos\AmazonMonitor\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
[ERROR]  TypeError: Cannot read properties of null (reading 'name')
    at Object.module.exports.run (C:\Users\rajsa\Documents\Git Repos\AmazonMonitor\commands\watch.js:96:19)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async exec (C:\Users\rajsa\Documents\Git Repos\AmazonMonitor\index.js:75:3)
C:\Users\rajsa\Documents\Git Repos\AmazonMonitor\node_modules\discord.js\src\rest\RequestHandler.js:154
      throw new DiscordAPIError(request.path, data, request.method, res.status);
            ^

DiscordAPIError: Cannot send an empty message
    at RequestHandler.execute (C:\Users\rajsa\Documents\Git Repos\AmazonMonitor\node_modules\discord.js\src\rest\RequestHandler.js:154:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async RequestHandler.push (C:\Users\rajsa\Documents\Git Repos\AmazonMonitor\node_modules\discord.js\src\rest\RequestHandler.js:39:14) {
  method: 'post',
  path: '/channels/905025694260678690/messages',
  code: 50006,
  httpStatus: 400
}
rajagrawal1 commented 3 years ago

Hi @SpikeHD can you help look into this?

SpikeHD commented 3 years ago

I will look into it soon

SpikeHD commented 3 years ago

Looked into it, seems like that category is laid out in a weird way compared to the other ones, so for now I have it suppressing the errors that come from it being a lil off, but I don't actually know whether the category watching itself will work for this one specifically. Apparently they can be more dynamic than I originally thought however long ago I pushed the original category watching update, which will require a much larger change that I simply don't have time for right now.

rajagrawal1 commented 3 years ago

@SpikeHD I understand, thank you for looking into this.

SpikeHD commented 3 years ago

Oh, right, and I'd also like to add an example for the required_perms section. Basically, it is a list of Discord permissions (which you can reference here) that will be required in order for someone to use the bot. If there are no valid permissions, anyone can use it, which is fine if you are in a server by yourself. But if you are in a server with many people, you may want to limit it to something like ADMINISTRATOR.

It would looks something like this:

// I just want anyone to use it
"required_perms": [],
// I want admins to use it
"required_perms": ["ADMINISTRATOR"],

etc.