#Discord Automod

50 messages · Page 1 of 1 (latest)

buoyant zealotBOT
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

sand holly
#

salon here would be a collection, spread its values into that array you pass there

#

And salons would be a Channel, not an array, so don’t [0] it

#

Maybe you meant to name them the other way around?

karmic apex
#

Something like that ? ```js
const salons = interaction.options.getChannel('channel');
const salon = rule.exemptChannels;

if (salon.size === 0) {
rule.edit({
name: test,
exemptChannels: [...salon],
});
} else {
rule.edit({
name: test,
exemptChannels: [...salons, ...salon],
});
}

#

no doesn't work

sand holly
#

No, as I said, salons is a single Channel here, not an iterable. So don’t spread it

karmic apex
sand holly
#

That looks better, yes.

karmic apex
# sand holly That looks better, yes.
Promise {
  <rejected> DiscordAPIError[50035]: Invalid Form Body
  exempt_channels[0][BASE_TYPE_REQUIRED]: This field is required
      at handleErrors (C:\Users\Phoenix\OneDrive\Bureau\Perso\Phoenix\V.14\node_modules\@discordjs\rest\dist\index.js:640:13)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async SequentialHandler.runRequest (C:\Users\Phoenix\OneDrive\Bureau\Perso\Phoenix\V.14\node_modules\@discordjs\rest\dist\index.js:1021:23)
      at async SequentialHandler.queueRequest (C:\Users\Phoenix\OneDrive\Bureau\Perso\Phoenix\V.14\node_modules\@discordjs\rest\dist\index.js:862:14)
      at async REST.request (C:\Users\Phoenix\OneDrive\Bureau\Perso\Phoenix\node_modules\@discordjs\rest\dist\index.js:1387:22)
      at async AutoModerationRuleManager.edit (C:\Users\Phoenix\OneDrive\Bureau\Perso\Phoenix\V.14\node_modules\discord.js\src\managers\AutoModerationRuleManager.js:177:18) {
    requestBody: { files: undefined, json: [Object] },
    rawError: { code: 50035, errors: [Object], message: 'Invalid Form Body' },
    code: 50035,
    status: 400,
    method: 'PATCH',
    url: 'https://discord.com/api/v10/guilds/1040942425922883634/auto-moderation/rules/1108050715248701582'
  }
}
sand holly
#

Ah, wait, salon will be a collection, you need to spread salon.values()

karmic apex
sand holly
karmic apex
sand holly
#

Without the code showing what you did there’s nothing I can help you with. Other than referring you to the docs

karmic apex
#

word is : word1, word2, word3

#

same when i edit

sand holly
#

Yeah, then it‘s one element in the array only…

karmic apex
#

so i should add words one by one ?

sand holly
#

You should pass them as array. Not stringify the list into one single element

karmic apex
sand holly
#

That‘s still an array with one single element. Please tell me you know how arrays work

karmic apex
#

const exemple = ['test1', 'test2', 'test3'];

sand holly
#

Yes, that is indeed an array

karmic apex
#

so when the member create his rule

obtuse galeBOT
#

mdn String.prototype.split()
The split() method takes a pattern and divides a String into an ordered list of substrings by searching for the pattern, puts these substrings into an array, and returns the array.

karmic apex
sand holly
#

That would be a nested array…

karmic apex
sand holly
#

That would indeed be a string array now, just as the function expects

karmic apex
karmic apex
sand holly
#

What did you try? And no need to reply-ping me, we‘re literally the only people in this thread

karmic apex
#

sorry, so i have tried a lot of things. The last i've tried is ```js
const valueToRemove = value; //Value is the id of the role
const exemptRoles = rule.exemptRoles;
const excludedRoles = Array.from(exemptRoles.values());

const updatedExemptRoles = exemptRoles.filter(role => !excludedRoles.includes(role) || role !== valueToRemove);

                rule.edit({
                    exemptRoles: updatedExemptRoles,
                    
                });
sand holly
karmic apex
sand holly
#

console.log(updatedExemptRoles) before the edit call there

#

And make sure rule is the one you mean to edit

karmic apex
sand holly
#

Ah, it’s the collection again, not an array…

#

But that should work

#

How many roles does the rule have exempt?

karmic apex
#

2

sand holly
#

Then all works correctly, no?

karmic apex
#

iam gonna check

#

yes the channels/roles exempt are working correctly