unable to make changes

i have made a automod command but i cant able to set punishment or logs
12 Replies
d.js toolkit
d.js toolkitโ€ข16mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
โ‹†หšเฟ” Soul ๐œ—๐œšหšโ‹†
await rule.edit({
actions: [
{
type: 1,
metadata: {
channel: alertChannel,
durationSeconds: durationSeconds,
customMessage: `This message has been blocked due to a blacklisted word. You have been timed out for ${timeoutDuration}.`,
},
},
],
});
await rule.edit({
actions: [
{
type: 1,
metadata: {
channel: alertChannel,
durationSeconds: durationSeconds,
customMessage: `This message has been blocked due to a blacklisted word. You have been timed out for ${timeoutDuration}.`,
},
},
],
});
its not setting the automod punishment and log channel idk why i have mention all things
let durationSeconds;

switch (timeoutDuration) {
case '60s':
durationSeconds = "60 secs";
break;
case '5m':
durationSeconds = "5 mins";
break;
case '10m':
durationSeconds = "10 mins";
break;
case '1h':
durationSeconds = "1 hour";
break;
case '1d':
durationSeconds = "1 day";
break;
case '1w':
durationSeconds = "1 week";
break;
}

const alertChannel = message.mentions.channels.first();
if (!alertChannel) {
return message.channel.send('Please mention a valid alert channel.');
}
let durationSeconds;

switch (timeoutDuration) {
case '60s':
durationSeconds = "60 secs";
break;
case '5m':
durationSeconds = "5 mins";
break;
case '10m':
durationSeconds = "10 mins";
break;
case '1h':
durationSeconds = "1 hour";
break;
case '1d':
durationSeconds = "1 day";
break;
case '1w':
durationSeconds = "1 week";
break;
}

const alertChannel = message.mentions.channels.first();
if (!alertChannel) {
return message.channel.send('Please mention a valid alert channel.');
}
i am setting it acc to the auto mod options so shall i do it in this form
let durationSeconds;

switch (timeoutDuration) {
case '60s':
durationSeconds = 60;
break;
case '5m':
durationSeconds = 5 * 60;
break;
case '10m':
durationSeconds = 10 * 60;
break;
case '1h':
durationSeconds = 60 * 60;
break;
case '1d':
durationSeconds = 24 * 60 * 60;
break;
case '1w':
durationSeconds = 7 * 24 * 60 * 60;
break;
}
let durationSeconds;

switch (timeoutDuration) {
case '60s':
durationSeconds = 60;
break;
case '5m':
durationSeconds = 5 * 60;
break;
case '10m':
durationSeconds = 10 * 60;
break;
case '1h':
durationSeconds = 60 * 60;
break;
case '1d':
durationSeconds = 24 * 60 * 60;
break;
case '1w':
durationSeconds = 7 * 24 * 60 * 60;
break;
}
? yeap its just blocking msgs
โ‹†หšเฟ” Soul ๐œ—๐œšหšโ‹†
i need to enable these 2 options too
โ‹†หšเฟ” Soul ๐œ—๐œšหšโ‹†
action name ? any docs for them ? automod in general
โ‹†หšเฟ” Soul ๐œ—๐œšหšโ‹†
ig these are the options
d.js docs
d.js docsโ€ข16mo ago
method AutoModerationRule#edit() Edits this auto moderation discord Auto Moderation: Modify Auto Moderation Rule read more
โ‹†หšเฟ” Soul ๐œ—๐œšหšโ‹†
kk yeap it worked just 1 thing the audit logs is shit
โ‹†หšเฟ” Soul ๐œ—๐œšหšโ‹†
why its saying unknown
await rule.edit({
actions: [
{
type: 1,
metadata: {
channel: logChannel,
durationSeconds: 0, // Set to 0 to disable message blocking
customMessage: `This message has been blocked due to a blacklisted word.`,
},
},
{
type: 2, // Alert channel action
metadata: {
channel: logChannel,
},
},
{
type: 3, // Timeout action
metadata: {
durationSeconds: durationSeconds,
},
},
],
});
await rule.edit({
actions: [
{
type: 1,
metadata: {
channel: logChannel,
durationSeconds: 0, // Set to 0 to disable message blocking
customMessage: `This message has been blocked due to a blacklisted word.`,
},
},
{
type: 2, // Alert channel action
metadata: {
channel: logChannel,
},
},
{
type: 3, // Timeout action
metadata: {
durationSeconds: durationSeconds,
},
},
],
});
k and that custom message is not working Oh wait ig i have declared custom message in wrong action it should be in timeout action 1 more question like i am making 2 different command 1 for timeout and 1 for log if i enable timeout then it remove log and if i add log it remove timeout how to fix it how i tried this but my brain is dying over and over
const logChannel = message.mentions.channels.first() || client_guild.channels.cache.get(value);

if (!logChannel) {
return message.channel.send('Please provide a valid log channel (mention or ID).');
}

const existingActions = rule.actions;
const updatedActions = [
{
type: 1,
metadata: existingActions[0].metadata,
},
{
type: 2, // Alert channel action
metadata: {
channel: logChannel,
},
},
{
type: 3, // Timeout action
metadata: existingActions.find(action => action.type === 3).metadata,
},
];

await rule.edit({
actions: updatedActions,
});
const logChannel = message.mentions.channels.first() || client_guild.channels.cache.get(value);

if (!logChannel) {
return message.channel.send('Please provide a valid log channel (mention or ID).');
}

const existingActions = rule.actions;
const updatedActions = [
{
type: 1,
metadata: existingActions[0].metadata,
},
{
type: 2, // Alert channel action
metadata: {
channel: logChannel,
},
},
{
type: 3, // Timeout action
metadata: existingActions.find(action => action.type === 3).metadata,
},
];

await rule.edit({
actions: updatedActions,
});
TypeError: Cannot read properties of undefined (reading 'metadata')
at Object.execute (/home/container/commands/automod/setpunishment.js:107:74)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
TypeError: Cannot read properties of undefined (reading 'metadata')
at Object.execute (/home/container/commands/automod/setpunishment.js:107:74)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
do you mean like this ??
return {
type: 2,
metadata: {
channel: message.mentions.channels.first() || client_guild.channels.cache.get(value),
},
};
} else {
return action; // Keep the action unchanged
}
});
return {
type: 2,
metadata: {
channel: message.mentions.channels.first() || client_guild.channels.cache.get(value),
},
};
} else {
return action; // Keep the action unchanged
}
});
kk bro idk what happened in the codes but now its not updating and my brain is dying please please can you see full code and tell why its acting i am fixing all things since 5 hours
d.js docs
d.js docsโ€ข16mo ago
If you aren't getting any errors, try to place console.log checkpoints throughout your code to find out where execution stops. โ€ข Once you do, log relevant values and if-conditions โ€ข More sophisticated debugging methods are breakpoints and runtime inspections: learn more
Want results from more Discord servers?
Add your server