mrjackyliang / discord-stonker-bot

An advanced business-ready bot built for finance-related Discord servers
MIT License
11 stars 1 forks source link

TSError: Unable to compile TypeScript #1

Closed bxpana closed 2 years ago

bxpana commented 2 years ago

Describe the bug:

What do you think the problem relates to?

Steps to reproduce the bug:

  1. Run Stonker Bot with npm start

Expected behavior:

The bot would start and be online on Discord

Logs related to this bug:

/home/pi/Documents/discord-stonker-bot/node_modules/ts-node/src/index.ts:750
    return new TSError(diagnosticText, diagnosticCodes);
           ^
TSError: ⨯ Unable to compile TypeScript:
src/modules/anti-raid.ts:1:43 - error TS2724: '"discord.js"' has no exported member named 'TextBasedChannels'. Did you mean 'TextBasedChannel'?

1 import { GuildMember, PartialGuildMember, TextBasedChannels } from 'discord.js';
                                            ~~~~~~~~~~~~~~~~~
src/modules/anti-raid.ts:172:15 - error TS7006: Parameter 'error' implicitly has an 'any' type.

172     }).catch((error) => generateLogMessage(
                  ~~~~~

    at createTSError (/home/pi/Documents/discord-stonker-bot/node_modules/ts-node/src/index.ts:750:12)
    at reportTSError (/home/pi/Documents/discord-stonker-bot/node_modules/ts-node/src/index.ts:754:19)
    at getOutput (/home/pi/Documents/discord-stonker-bot/node_modules/ts-node/src/index.ts:941:36)
    at Object.compile (/home/pi/Documents/discord-stonker-bot/node_modules/ts-node/src/index.ts:1243:30)
    at Module.m._compile (/home/pi/Documents/discord-stonker-bot/node_modules/ts-node/src/index.ts:1370:30)
    at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Object.require.extensions.<computed> [as .ts] (/home/pi/Documents/discord-stonker-bot/node_modules/ts-node/src/index.ts:1374:12)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19) {
  diagnosticText: `\x1B[96msrc/modules/anti-raid.ts\x1B[0m:\x1B[93m1\x1B[0m:\x1B[93m43\x1B[0m - \x1B[91merror\x1B[0m\x1B[90m TS2724: \x1B[0m'"discord.js"' has no exported member named 'TextBasedChannels'. Did you mean 'TextBasedChannel'?\n` +
    '\n' +
    "\x1B[7m1\x1B[0m import { GuildMember, PartialGuildMember, TextBasedChannels } from 'discord.js';\n" +
    '\x1B[7m \x1B[0m \x1B[91m                                          ~~~~~~~~~~~~~~~~~\x1B[0m\n' +
    "\x1B[96msrc/modules/anti-raid.ts\x1B[0m:\x1B[93m172\x1B[0m:\x1B[93m15\x1B[0m - \x1B[91merror\x1B[0m\x1B[90m TS7006: \x1B[0mParameter 'error' implicitly has an 'any' type.\n" +
    '\n' +
    '\x1B[7m172\x1B[0m     }).catch((error) => generateLogMessage(\n' +
    '\x1B[7m   \x1B[0m \x1B[91m              ~~~~~\x1B[0m\n',
  diagnosticCodes: [ 2724, 7006 ]
}
bxpana commented 2 years ago

Could this have anything to do with my inputs on my config.json?

mrjackyliang commented 2 years ago

Can I see the copy of your package.json?

bxpana commented 2 years ago

I didn't make any changes, but here is what I have:

{
    "name": "discord-stocker-bot",
    "displayName": "Discord Stonker Bot",
    "version": "2.0.0",
    "description": "A Discord bot built for finance-related servers",
    "main": "build/src/index.js",
    "private": true,
    "scripts": {
        "start": "ts-node src/index.ts",
        "build": "npm-run-all -p build:*",
        "build:tsc": "tsc --build",
        "build:copyfiles": "copyfiles -u 1 src/**/*.ejs build/src/"
    },
    "repository": {
        "type": "git",
        "url": "git://github.com/mrjackyliang/discord-stonker-bot.git"
    },
    "funding": {
        "type": "github",
        "url": "https://github.com/sponsors/mrjackyliang"
 },
    "keywords": [
        "discord",
        "discord-bot",
        "stocks",
        "moderation",
        "scheduler",
        "auto-reply"
    ],
    "author": "Jacky Liang",
    "license": "ISC",
    "bugs": {
        "url": "https://github.com/mrjackyliang/discord-stonker-bot/issues"
    },
    "files": [],
    "homepage": "https://github.com/mrjackyliang/discord-stonker-bot#readme",
    "engines": {
        "node": "16"
    },
"dependencies": {
        "axios": "^0.21.1",
        "chalk": "^4.1.0",
        "discord.js": "^13.1.0",
        "ejs": "^3.1.6",
        "express": "^4.17.1",
        "lodash": "^4.17.21",
        "luxon": "^2.0.2",
        "node-schedule": "^2.0.0",
        "rss-parser": "^3.12.0"
    },
    "devDependencies": {
        "@types/express": "^4.17.13",
        "@types/lodash": "^4.14.172",
        "@types/luxon": "^2.0.2",
        "@types/node": "^17.0.8",
        "@types/node-schedule": "^1.3.2",
        "@types/xml2js": "^0.4.9",
"@typescript-eslint/eslint-plugin": "^4.29.1",
        "@typescript-eslint/parser": "^4.29.1",
        "copyfiles": "^2.4.1",
        "eslint": "^7.32.0",
        "eslint-config-airbnb-base": "^14.2.1",
        "eslint-plugin-import": "^2.24.0",
        "npm-run-all": "^4.1.5",
        "ts-node": "^10.4.0",
        "tslib": "^2.3.1",
        "typescript": "^4.3.5"
    }
}
mrjackyliang commented 2 years ago
"@types/node": "^17.0.8",
"ts-node": "^10.2.0",
"tslib": "^2.3.1",

these are extra packages not included in the original release

bxpana commented 2 years ago

So those need to be removed?

mrjackyliang commented 2 years ago

If you've installed extra packages, yes. They have not been tested with the latest release.

bxpana commented 2 years ago

I removed them from my package.json but still getting the error. Does it matter if I'm running this on a Raspberry Pi?

/home/pi/Documents/discord-stonker-bot/node_modules/ts-node/src/index.ts:750
    return new TSError(diagnosticText, diagnosticCodes);
           ^
TSError: ⨯ Unable to compile TypeScript:
src/modules/anti-raid.ts:1:43 - error TS2724: '"discord.js"' has no exported member named 'TextBasedChannels'. Did you mean 'TextBasedChannel'?

1 import { GuildMember, PartialGuildMember, TextBasedChannels } from 'discord.js';
                                            ~~~~~~~~~~~~~~~~~
src/modules/anti-raid.ts:172:15 - error TS7006: Parameter 'error' implicitly has an 'any' type.

172     }).catch((error) => generateLogMessage(
                  ~~~~~

    at createTSError (/home/pi/Documents/discord-stonker-bot/node_modules/ts-node/src/index.ts:750:12)
    at reportTSError (/home/pi/Documents/discord-stonker-bot/node_modules/ts-node/src/index.ts:754:19)
    at getOutput (/home/pi/Documents/discord-stonker-bot/node_modules/ts-node/src/index.ts:941:36)
    at Object.compile (/home/pi/Documents/discord-stonker-bot/node_modules/ts-node/src/index.ts:1243:30)
    at Module.m._compile (/home/pi/Documents/discord-stonker-bot/node_modules/ts-node/src/index.ts:1370:30)
    at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Object.require.extensions.<computed> [as .ts] (/home/pi/Documents/discord-stonker-bot/node_modules/ts-node/src/index.ts:1374:12)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19) {
  diagnosticText: `\x1B[96msrc/modules/anti-raid.ts\x1B[0m:\x1B[93m1\x1B[0m:\x1B[93m43\x1B[0m - \x1B[91merror\x1B[0m\x1B[90m TS2724: \x1B[0m'"discord.js"' has no exported member named 'TextBasedChannels'. Did you mean 'TextBasedChannel'?\n` +
    '\n' +
    "\x1B[7m1\x1B[0m import { GuildMember, PartialGuildMember, TextBasedChannels } from 'discord.js';\n" +
    '\x1B[7m \x1B[0m \x1B[91m                                          ~~~~~~~~~~~~~~~~~\x1B[0m\n' +
    "\x1B[96msrc/modules/anti-raid.ts\x1B[0m:\x1B[93m172\x1B[0m:\x1B[93m15\x1B[0m - \x1B[91merror\x1B[0m\x1B[90m TS7006: \x1B[0mParameter 'error' implicitly has an 'any' type.\n" +
    '\n' +
    '\x1B[7m172\x1B[0m     }).catch((error) => generateLogMessage(\n' +
    '\x1B[7m   \x1B[0m \x1B[91m              ~~~~~\x1B[0m\n',
  diagnosticCodes: [ 2724, 7006 ]
}
mrjackyliang commented 2 years ago

Try reinstalling the bot and re-add your configuration in there

mrjackyliang commented 2 years ago

And tell me the commands you used to compile the bot

bxpana commented 2 years ago

You mean my config.json? I'm pretty new to hosting Discord bots so I appreciate your help.

Do I need to do anything with what I have now or just copy the repo in a different file and try running the bot again after configuring?

mrjackyliang commented 2 years ago

You mean my config.json? I'm pretty new to hosting Discord bots so I appreciate your help.

Do I need to do anything with what I have now or just copy the repo in a different file and try running the bot again after configuring?

Correct. The config.json file is not included in the original repo, so you can copy the examples from config-sample.json.

Try copying the repo into a different folder, do npm install && npm build && npm start

bxpana commented 2 years ago

config.json (without my bot token)

{

  "settings": {

    "client-token": "MY_TOKEN",

    "guild-id": "722409280497516566",

    "bot-prefix": "!",

    "server-http-port": 8080,

    "server-https-port": 8443,

    "server-https-key": "",

    "server-https-cert": "",

    "server-https-ca": "",

    "time-zone": "Etc/UTC",

    "log-level": 30

  },

  "snitch": {

    "change-nickname": {

      "channel-id": "927961532644601887"

    },

    "change-username": {

      "channel-id": "927961532644601887"

    },

    "delete-message": {

      "channel-id": ""

    },

    "includes-link": {

      "channel-id": ""

    },

    "update-message": {

      "channel-id": ""

    },

    "upload-attachment": {

      "channel-id": ""

    }

  },

  "commands": {

    "bulk-ban": [

      {

        "description": "Sample role",

        "id": "000000000000000000"

      }

    ],

    "fetch-duplicates": [

      {

        "description": "Sample role",

        "id": "000000000000000000"

      }

    ],

    "fetch-members": [

      {

        "description": "Sample role",

        "id": "000000000000000000"

      }

    ],

    "help-menu": [

      {

        "description": "Sample role",

        "id": "000000000000000000"

      }

    ],

    "role-manager": [

      {

        "description": "Sample role",

        "id": "000000000000000000"

      }

    ],

    "toggle-perms": [

      {

        "description": "Sample role",

        "id": "000000000000000000"

      }

    ],

    "voice-tools": [

      {

        "description": "Sample role",

        "id": "000000000000000000"

      }

    ]

  },

  "api-fetch": {

    "etherscan-gas-oracle": {

      "feed": {

        "channel-id": ""

      },

      "command": {

        "regex": {

          "pattern": "(?:)",

          "flags": "g"

        },

        "allowed-roles": [

          {

            "description": "Sample role",

            "id": "000000000000000000"

          }

        ]

      }

    },

    "stocktwits-trending": {

      "feed": {

        "channel-id": ""

      },

      "command": {

        "regex": {

          "pattern": "(?:)",

          "flags": "g"

        },

        "allowed-roles": [

          {

            "description": "Sample role",

            "id": "000000000000000000"

          }

        ]

      }

    }

  },

  "anti-raid": {

    "auto-ban": {

      "avatar": [

        "37cb8a08bcba4e2a909a4404550c81f2", "53d8b20879c56b05819a5159904bb1da"

      ],

      "username": [

        "Bad User"

      ]

    },

    "membership-gate": {

      "role-id": "000000000000000000",

      "channel-id": "000000000000000000",

      "message": "Welcome to %GUILD_NAME%! Thank you for verifying, %MEMBER_MENTION%."

    },

    "monitor": {

      "guild-join": {

        "channel-id": "000000000000000000"

      },

      "guild-leave": {

        "channel-id": "000000000000000000"

      }

    }

  },

  "schedule-posts": [

    {

      "name": "Sample",

      "channel-id": "000000000000000000",

      "payload": {

        "content": "This is a sample scheduled post"

      },

      "reactions": [

        "🟢",

        "🟡",

        "🔴"

      ],

      "send-every": {

        "time-zone": "Etc/UTC",

        "days-of-week": [

          0,

          1,

          2,

          3,

          4,

          5,

          6

        ],

        "year": [

          2020

        ],

        "month": [

          0

        ],

        "date": [

          1

        ],

        "hour": [

          0

        ],

        "minute": [

          0

        ],

        "second": [

          0

        ]

      },

      "skip-days": [

        "2021-01-01",

        "2021-02-01"

      ]

    }

  ],

  "rss-feeds": [

    {

      "name": "Sample",

      "channel-id": "000000000000000000",

      "interval": "* * * * *",

      "url": "https://www.example.com/feed",

      "message": "Sample: %ITEM_TITLE% - %ITEM_LINK%"

    }

  ],

  "regex-rules": [

    {

      "name": "Sample Regex",

      "channel-id": "000000000000000000",

      "regex": {

        "pattern": "(?:)",

        "flags": "g"

      },

      "direct-message": "This type of text is not allowed in this channel!",

      "exclude-roles": [

        {

          "description": "Sample role",

          "id": "000000000000000000"

        }

      ]

    }

  ],

  "suspicious-words": {

    "channel-id": "000000000000000000",

    "categories": [

      {

        "category": "Sample",

        "words": [

          "suspicious",

          "really suspicious"

        ]

      }

    ]

  },

  "roles": [

    {

      "name": "Remove B role if member is A",

      "type": "yes-to-yes",

      "before": [

        {

          "description": "A role",

          "id": "000000000000000000"

        }

      ],

      "after": [

        {

          "description": "A role",

          "id": "000000000000000000"

        }

      ],

      "to-remove": [

        {

          "description": "B role",

          "id": "000000000000000000"

        }

      ]

    },

    {

      "name": "Remove B role if member is not A",

      "type": "no-to-no",

      "before": [

        {

          "description": "A role",

          "id": "000000000000000000"

        }

      ],

      "after": [

        {

          "description": "A role",

          "id": "000000000000000000"

        }

      ],

      "to-remove": [

        {

          "description": "B role",

          "id": "000000000000000000"

        }

      ]

    },

    {

      "name": "Add B role if member went from A to not A",

      "type": "yes-to-no",

      "before": [

        {

          "description": "A role",

          "id": "000000000000000000"

        }

      ],

      "after": [

        {

          "description": "A role",

          "id": "000000000000000000"

        }

      ],

      "to-add": [

        {

          "description": "B role",

          "id": "000000000000000000"

        }

      ]

    },

    {

      "name": "Remove B role if member went from not A to A",

      "type": "no-to-yes",

      "before": [

        {

          "description": "A role",

          "id": "000000000000000000"

        }

      ],

      "after": [

        {

          "description": "A role",

          "id": "000000000000000000"

        }

      ],

      "to-remove": [

        {

          "description": "B role",

          "id": "000000000000000000"

        }

      ]

    }

  ],

  "auto-reply": [

    {

      "name": "Sample",

      "channel-ids": [

        "000000000000000000"

      ],

      "reply": true,

      "regex": {

        "pattern": "(?:)",

        "flags": "gi"

      },

      "messages": [

        "reply 1",

        "reply 2"

      ]

    }

  ],

  "message-copier": [

    {

      "name": "Sample",

      "channel-id": "000000000000000000",

      "regex": {

        "pattern": "(?:)",

        "flags": "g"

      },

      "replacements": [

        {

          "pattern": "",

          "flags": "",

          "replace-with": ""

        }

      ],

      "format": "Author Mention: %AUTHOR_MENTION%\nAuthor Tag: %AUTHOR_TAG%\nChannel Mention: %CHANNEL_MENTION%\nMessage Content: %MESSAGE_CONTENT%\nMessage Excerpt: %MESSAGE_EXCERPT%\nMessage URL: %MESSAGE_URL%",

      "include-attachments": true,

      "delete-message": false,

      "allowed-users": [

        "000000000000000000"

      ],

      "allowed-channels": [

        "000000000000000000"

      ],

      "disallowed-users": [

        "000000000000000000"

      ],

      "disallowed-channels": [

        "000000000000000000"

      ]

    }

  ],

  "affiliate-links": {

    "links": [

      {

        "website": "Affiliate Company",

        "regex": {

          "pattern": "(?:)",

          "flags": "gi"

        }

      }

    ],

    "channel-id": "000000000000000000",

    "direct-message": "Please do not send affiliate links!",

    "excluded-roles": [

      {

        "description": "Sample role",

        "id": "000000000000000000"

      }

    ]

  },

  "invite-generator": {

    "path": "/invite",

    "options": {

      "max-age": 120,

      "max-uses": 1

    },

    "design": {

      "logo-url": "",

      "favicon-url": "",

      "background-color": "",

      "link-color": "",

      "text-color": ""

    },

    "inject-code": {

      "header": "",

      "submit-success": "",

      "submit-fail": ""

    },

    "recaptcha": {

      "site-key": "",

      "secret-key": ""

    }

  },

  "toggle-perms": [

    {

      "name": "Sample",

      "id": "sample",

      "on": [

        {

          "description": "#sample-channel",

          "channel-id": "000000000000000000",

          "channel-perms": [

            {

              "description": "Sample role",

              "user-or-role-id": "000000000000000000",

              "user-or-role-perms": {

                "SEND_MESSAGES": false

              }

            }

          ]

        }

      ],

      "off": [

        {

          "description": "#sample-channel",

          "channel-id": "000000000000000000",

          "channel-perms": [

            {

              "description": "Sample role",

              "user-or-role-id": "000000000000000000",

              "user-or-role-perms": {

                "SEND_MESSAGES": false

              }

            }

          ]

        }

      ]

    }

  ],

  "bump-threads": [

    {

      "name": "#sample-channel",

      "channel-id": "000000000000000000",

      "thread-id": "000000000000000000"

    }

  ]

}
bxpana commented 2 years ago

Had to to npm run build instead because npm build was not recognized and got this error:

> discord-stocker-bot@2.0.0 build
> npm-run-all -p build:*

> discord-stocker-bot@2.0.0 build:tsc
> tsc --build

> discord-stocker-bot@2.0.0 build:copyfiles
> copyfiles -u 1 src/**/*.ejs build/src/

src/modules/anti-raid.ts:1:43 - error TS2724: '"discord.js"' has no exported member named 'TextBasedChannels'. Did you mean 'TextBasedChannel'?

1 import { GuildMember, PartialGuildMember, TextBasedChannels } from 'discord.js';
                                            ~~~~~~~~~~~~~~~~~

src/modules/anti-raid.ts:172:15 - error TS7006: Parameter 'error' implicitly has an 'any' type.

172     }).catch((error) => generateLogMessage(
                  ~~~~~

src/modules/commands.ts:6:3 - error TS2724: '"discord.js"' has no exported member named 'TextBasedChannels'. Did you mean 'TextBasedChannel'?

6   TextBasedChannels,
    ~~~~~~~~~~~~~~~~~

src/modules/commands.ts:59:13 - error TS7006: Parameter 'error' implicitly has an 'any' type.

59   }).catch((error) => generateLogMessage(
               ~~~~~

src/modules/commands.ts:90:13 - error TS7006: Parameter 'error' implicitly has an 'any' type.

90   }).catch((error) => generateLogMessage(
               ~~~~~

src/modules/commands.ts:122:13 - error TS7006: Parameter 'error' implicitly has an 'any' type.

122   }).catch((error) => generateLogMessage(
                ~~~~~

src/modules/content.ts:1:10 - error TS2724: '"discord.js"' has no exported member named 'TextBasedChannels'. Did you mean 'TextBasedChannel'?

1 import { TextBasedChannels } from 'discord.js';
           ~~~~~~~~~~~~~~~~~

src/modules/content.ts:196:23 - error TS7006: Parameter 'error' implicitly has an 'any' type.

196             }).catch((error) => generateLogMessage(
                          ~~~~~

src/modules/content.ts:314:43 - error TS7006: Parameter 'post' implicitly has an 'any' type.

314         sendToChannel.send(payload).then((post) => {
                                              ~~~~

src/modules/content.ts:331:23 - error TS7006: Parameter 'error' implicitly has an 'any' type.

331             )).catch((error) => generateLogMessage(
                          ~~~~~

src/modules/content.ts:340:19 - error TS7006: Parameter 'error' implicitly has an 'any' type.

340         }).catch((error) => generateLogMessage(
                      ~~~~~

Found 11 errors.
mrjackyliang commented 2 years ago

Can I see a copy of your TypeScript configuration as well?

bxpana commented 2 years ago

tsconfig.json

{
    "compilerOptions": {
        "allowJs": true,
        "allowSyntheticDefaultImports": true,
        "esModuleInterop": true,
        "forceConsistentCasingInFileNames": true,
        "module": "CommonJS",
        "moduleResolution": "Node",
        "noFallthroughCasesInSwitch": true,
        "noImplicitAny": true,
        "noImplicitReturns": true,
        "noUnusedLocals": true,
        "outDir": "./build",
        "removeComments": true,
        "resolveJsonModule": true,
        "sourceMap": true,
        "strict": true,
        "target": "ES2020"
    },
    "include": [
           "./src"
    ]
}
mrjackyliang commented 2 years ago

Hmm I am stumped. Can you try running this on your computer instead? I have this bot running on Google Cloud and on my computer, never seen this issue before.

bxpana commented 2 years ago

Yeah I'll test it out and report back

bxpana commented 2 years ago

I tried running on my Mac and still getting the same errors.

TSError: ⨯ Unable to compile TypeScript:
src/modules/anti-raid.ts:1:43 - error TS2724: '"discord.js"' has no exported member named 'TextBasedChannels'. Did you mean 'TextBasedChannel'?

1 import { GuildMember, PartialGuildMember, TextBasedChannels } from 'discord.js';
                                            ~~~~~~~~~~~~~~~~~
src/modules/anti-raid.ts:172:15 - error TS7006: Parameter 'error' implicitly has an 'any' type.

172     }).catch((error) => generateLogMessage(
bxpana commented 2 years ago

Does it have to do with TextBasedChannels since that is always the same issue?

mrjackyliang commented 2 years ago

TextBasedChannels is the correct import. It's part of the discord.js documentation.

mrjackyliang commented 2 years ago

Can you try these commands and output it here:

npm list -g --depth=0
node -v
bxpana commented 2 years ago

Mac: npm list:

/usr/local/lib
├── corepack@0.10.0
└── npm@8.3.0

Node Version:

v16.13.0
mrjackyliang commented 2 years ago

Actually, after I re-installed the node modules, I can re-produce the same error. Working on it atm!

mrjackyliang commented 2 years ago

Now this is interesting. I updated all the packages, and type references and it all works. Looks like I'm going to push a bugfix version up by tonight! Sorry for the wait!

bxpana commented 2 years ago

Awesome!! No worries, just glad you got it figured out. I'll check it out later to see if I can get it working once the fix is pushed.

mrjackyliang commented 2 years ago

Yeah, I just haven't updated the packages in a while probably that was why it caused all the weird errors. But I fixed it, and adding some enhancements, then I'll deploy a new one

mrjackyliang commented 2 years ago

I've published v2.0.1! Going to close this issue for now. If the same problem persists, let me know and I'll re-open it.

github-actions[bot] commented 10 months ago

This issue is now locked and considered resolved. If you have questions or inquiries, you may start a new issue.