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

AutoMod MentionSpam Rule Error #9287

Closed
CaptainPlantain opened this issue Mar 28, 2023 · 5 comments
Closed

AutoMod MentionSpam Rule Error #9287

CaptainPlantain opened this issue Mar 28, 2023 · 5 comments

Comments

@CaptainPlantain
Copy link

Which package is this bug report for?

discord.js

Issue description

When attempting to modify the MentionSpam trigger type of AutoModerationRule (Block Mention Spam automod rule), methods are returning a 404 API error. All other trigger types for automod rules work without error.

Unhandled promise rejection: DiscordAPIError[0]: 404: Not Found
 {
  rawError: { message: '404: Not Found', code: 0 },
  code: 0,
  status: 404,
  method: 'PATCH',
  url: 'https://discord.com/api/v10/guilds/1013542833334005791/auto-moderation/rules/1030554520465440818',
  requestBody: {
    files: undefined,
    json: {
      name: undefined,
      event_type: undefined,
      trigger_metadata: undefined,
      actions: undefined,
      enabled: false,
      exempt_roles: undefined,
      exempt_channels: undefined
    }
  }
}

Code sample

const automodRules = await interaction.guild.autoModerationRules.fetch();
const mentionSpamRule = automodRules
  .find((rule) => rule.triggerType === AutoModerationRuleTriggerType.MentionSpam);
await mentionSpamRule.setEnabled(false);

Package version

14.8.0

Node.js version

18.13.0

Operating system

No response

Priority this issue should have

Medium (should be fixed soon)

Which partials do you have configured?

Not applicable (subpackage bug)

Which gateway intents are you subscribing to?

Not applicable (subpackage bug)

I have tested this issue on a development release

No response

@Jiralite
Copy link
Member

Jiralite commented Mar 28, 2023

Cannot reproduce. Provided code sample works perfectly fine. Tested both disabling and enabling on 14.8.0 and d1ebe4a.

image

image

After checking the code, I cannot see where this would fail:

setEnabled(enabled = true, reason) {
return this.edit({ enabled, reason });
}

edit(options) {
return this.guild.autoModerationRules.edit(this.id, options);
}

async edit(
autoModerationRule,
{ name, eventType, triggerMetadata, actions, enabled, exemptRoles, exemptChannels, reason },
) {
const autoModerationRuleId = this.resolveId(autoModerationRule);
const data = await this.client.rest.patch(Routes.guildAutoModerationRule(this.guild.id, autoModerationRuleId), {
body: {
name,
event_type: eventType,
trigger_metadata: triggerMetadata && {
keyword_filter: triggerMetadata.keywordFilter,
regex_patterns: triggerMetadata.regexPatterns,
presets: triggerMetadata.presets,
allow_list: triggerMetadata.allowList,
mention_total_limit: triggerMetadata.mentionTotalLimit,
},
actions: actions?.map(action => ({
type: action.type,
metadata: {
duration_seconds: action.metadata?.durationSeconds,
channel_id: action.metadata?.channel && this.guild.channels.resolveId(action.metadata.channel),
custom_message: action.metadata?.customMessage,
},
})),
enabled,
exempt_roles: exemptRoles?.map(exemptRole => this.guild.roles.resolveId(exemptRole)),
exempt_channels: exemptChannels?.map(exemptChannel => this.guild.channels.resolveId(exemptChannel)),
},
reason,
});

The data in your error is all correct. Therefore, I can only theorise that your provided code sample is not what you are actually doing, and you have reassigned the id in some way you have not shown.

@Jiralite Jiralite removed their assignment Mar 28, 2023
@CaptainPlantain
Copy link
Author

The code sample is exactly what I'm using and it worked just fine for all other rule types.
Oddly, I just ran into a 404 error when messing with a MentionSpam rule in the discord client which makes me think this is a client-side issue and not a discord.js issue.

@Jiralite
Copy link
Member

I just ran into a 404 error when messing with a MentionSpam rule in the discord client which makes me think this is a client-side issue and not a discord.js issue.

Definitely not a client-side issue if the API is returning it! If that's the case, then Discord thinks you do not have one, which is odd...

What is the output of mentionSpamRule in your code sample?

@CaptainPlantain
Copy link
Author

Looks normal to me. Still running into the error.

Here's mentionSpamRule

AutoModerationRule {
  id: '1030554520465440818',
  guild: Guild { ... }, 
  creatorId: '1008776202191634432',
  triggerType: 5,
  name: 'Block Mention Spam',
  eventType: 1,
  triggerMetadata: {
    keywordFilter: [],
    regexPatterns: [],
    presets: [],
    allowList: [],
    mentionTotalLimit: 20
  },
  actions: [ { type: 1, metadata: [Object] } ],
  enabled: true,
  exemptRoles: Collection(0) [Map] {},
  exemptChannels: Collection(0) [Map] {}
}

@Jiralite
Copy link
Member

Jiralite commented Mar 28, 2023

Honestly not sure at this point. If both the client and API can't do such an action, then it's not related to discord.js. Sounds more like a Discord issue.

I'd probably try deleting the rule and recreating it and see if that works.

@Jiralite Jiralite closed this as not planned Won't fix, can't repro, duplicate, stale Mar 30, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants