owengombas / discord.ts

🤖 Create your discord bot by using TypeScript and decorators!
https://owencalvin.github.io/discord.ts/
324 stars 40 forks source link

The slash command does not execute correctly #50

Closed cristianireyes closed 3 years ago

cristianireyes commented 3 years ago

I am testing the forward slash commands with the following example project: https://github.com/OwenCalvin/discord.ts-starter.git

Also update the @typeit/discord dependency to its latest available version: 5.0.11

{
  "dependencies": {
    "@typeit/discord": "^5.0.11",
    "discord.js": "github:discordjs/discord.js",
    "reflect-metadata": "^0.1.13"
  },
  "devDependencies": {
    "@types/node": "^15.6.0",
    "ts-node": "^9.1.1",
    "tslib": "^2.2.0",
    "typescript": "^4.2.4"
  }
}

The problem I found is when executing a command within a group. It seems that the command tree cannot be calculated correctly and returns undefined. For better understanding I provide screenshots of debugging.

Analysis:

  1. I run my command on my discord server 1

  2. The interaction arrived successfully and get the interaction group tree 2

  3. At this point, when trying to execute the getOptionsTree method on line 223, the variable _a takes the value of undefined in its second iteration 3 3bis

  4. And finally the getInteractionGroupTree method ends up returning the following 4

  5. Then it tries to retrieve slash from tree, accessing by case 1, but the conditions are never met because it tries to compare the group name with the command name, which is wrong 5

  6. And consequently, it ends up returning slash undefined 6

This causes the command to fail by not executing the slash 7

Try to be as detailed as possible so that I can share my analysis.

Thanks for your time Regards ✌🏻

owengombas commented 3 years ago

Thank's !

discord.js changed the options field from an array to a Map, it causes this issue, I fixed it you can now update the package by running npm run update and verify that your version is now 5.0.12 !

:)

cristianireyes commented 3 years ago

Thank's !

discord.js changed the options field from an array to a Map, it causes this issue, I fixed it you can now update the package by running npm run update and verify that your version is now 5.0.12 !

:)

Thanks for your quick resolution. Works!

works