Snazzah/slash-create-worker

requiredPermissions does not work (hangs command execution)

Erisa opened this issue · 2 comments

Erisa commented

Attempting to use requiredPermissions in seemingly any form results in the command hanging infinitely and timing out.

This appears to happen with both 5.4.1 and 5.5.0 of slash-create.

This does not happen on the plain JavaScript template. I have not tested any templates other this one and a plain JavaScript one.

Steps followed for repro:

  • Clone or degit clone the repo.
  • Install deps: yarn
  • Populate the env with DISCORD_APP_ID, DISCORD_PUBLIC_KEY, DISCORD_BOT_TOKEN and DEVELOPMENT_GUILD_ID like normal.
  • Add a command that uses requiredPermissions or modify an existing command to use it.
    • I tried both ['MANAGE_ROLES'] for my own command ['MANAGE_GUILD'] for a test command taken from the docs (see below).
  • Run yarn sync:dev
  • Run yarn dev
  • As a user with permission to use it, try to execute the command.

Expected:
image

Actual result:
image

Environment used:
Ubuntu 22.04 in WSL2 with node 16.14.0 from asdf.
Also happened on a GitHub Codespace default image with node 16 from nvm.

The output is kind of uninteresting because it seems to think everything is okay:

[mf:inf] Build succeeded
[mf:inf] Worker reloaded! (118.09KiB)
[mf:inf] Listening on :8787
[mf:inf] - http://127.0.0.1:8787
[mf:inf] - http://172.31.173.117:8787
[mf:inf] - http://172.18.0.1:8787
POST / 200 OK (2011.30ms, waitUntil: 2011.34ms)

Command used for repro was taken from docs:

const { SlashCommand, ApplicationCommandPermissionType } = require('slash-create');

module.exports = class ExclusivityCommand extends SlashCommand {
  constructor(creator) {
    super(creator, {
      name: 'exclusivity',
      description: 'Only people who manage the guild can use this command.',
      // Whether to enable this command for everyone by default
      defaultPermission: false,
      // This will be an array of permission flag names from here: https://discord.dev/topics/permissions#permissions-bitwise-permission-flags
      requiredPermissions: ['MANAGE_GUILD']
    });

    this.filePath = __filename;
  }

  async run(ctx) {
    return 'You can manage this guild!';
  }
}

Small oversight in the Bitfield, since the worker file is minified, this line isn't forcing the bit to be BigInt, making it mix BigInt with regular numbers and erroring out the whole execution. Will fix this in next release.

https://github.com/Snazzah/slash-create/blob/a9b0a910fa9d799151963b1e139d842150ef1a63/src/util/bitfield.ts#L106

Updated slash-create to v5.5.2 and updated the template.