Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing typing for MessageReaction #5002

Closed
1 task
itsa-sh opened this issue Nov 10, 2020 · 0 comments · Fixed by #5003
Closed
1 task

Missing typing for MessageReaction #5002

itsa-sh opened this issue Nov 10, 2020 · 0 comments · Fixed by #5003

Comments

@itsa-sh
Copy link
Contributor

itsa-sh commented Nov 10, 2020

Please describe the problem you are having in as much detail as possible:

When trying to handle the messageReactionAdd event, the client is inaccessible from the MessageReaction type.

client is being set using Object.assign so I can see it exists, although the type is missing this definition.

Include a reproducible code sample here, if possible:

@Injectable()
export class BotService {
  constructor(
    @Inject(discordConfig.KEY) private readonly config: ConfigType<typeof discordConfig>,
    private readonly moduleRef: ModuleRef,
    private readonly discord: DiscordClient,
    private readonly logger: Logger
  ) {}

  // ...

  async start(): Promise<string> {
      // this.discord.on('ready', this.isReady);
      // this.discord.on('message', this.handleMessage);
      this.discord.on('messageReactionAdd', this.handleMessageReactionAdd);

      return this.discord.login(this.config.key);
  }

  handleMessageReactionAdd = async (reaction: MessageReaction, user: User): Promise<void> => {
    try {
      const guild = reaction.client.guilds.cache.get(this.config.guildId);
      //                       ^ this is the type error ☹️ (my current work around is this.discord, but not ideal)
      const role = guild.roles.cache.get(this.config.memberRoleId);

      await (new GuildMemberRoleManager(guild.member(user))).add(role);

      this.logger.log(`user ${user.tag} accepted the community rules`);
    } catch (e) {
      this.logger.error(e.message);
    }
  }

  // ...
}

Further details:

  • discord.js version: ^12.4.1
  • Node.js version: 14.12.0
  • Operating system: Linux
  • Priority this issue should have – Low (Tho, I'm happy to do PR)

Relevant client options:

  • partials: none
  • gateway intents: none
  • other: none
  • I have also tested the issue on latest master, commit hash:
@SpaceEEC SpaceEEC linked a pull request Nov 11, 2020 that will close this issue
5 tasks
SpaceEEC pushed a commit that referenced this issue Nov 17, 2020
close #5002

Co-authored-by: Ashley Meadows <itsa-sh@users.noreply.github.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants