Check failing code
danicathh
HOBBYOP

a year ago

Hey, i have this code that’s not properly running through my bot. My hosting service works fine but when i try to use the commands it doesn’t go through. If you need the entire GitHub repo pls let me know. I was trying to create a warn feature where it would have a time included in the warn to then be removed from the warnings after a set amount of time. And perm warns for it to be permanently there.

const { client } = require("../index");
const warns = require('../schemas/warns');

module.exports = {
name: 'warn',
description: 'warn a user',
async execute(message, args) {
if (!message.member.permissions.has('MANAGE_MESSAGES')) return;
const warnUser = message.guild.members.cache.get(args[1]) || message.mentions.members?.first()
if (!warnUser) return message.react("❌");
if (args[0] === ">permwarn") {
if (args[2]) {
actionPost({
msg: message,
u: warnUser,
a: "warn",
r: message.content.substring(>permwarn ${[warnUser.id](warnUser.id)}.length),
s: "permwarn"
});
} else {
return message.react("❌");
}
}

else if (args[0] === ">warn") {
  if (args[2] && Number(args[2]) && Number(args[2]) > 0 && Number(args[2]) < 6) {
    let time = args[3]; 
    if (time) {

      actionPost({ 
        msg: message, 
        u: warnUser, 
        a: "warn", 
        r: message.content.substring(`>warn ${[warnUser.id](warnUser.id)} ${args[2]} `.length), 
        s: Number(args[2]),
        expTime: time 
      });

      const ms = msToMilliseconds(time); 
      setTimeout(() => {
        console.log(`Warning for ${warnUser.tag} expired.`);
      }, ms);
    } else {
      actionPost({ 
        msg: message, 
        u: warnUser, 
        a: "warn", 
        r: message.content.substring(`>warn ${[warnUser.id](warnUser.id)} `.length), 
        s: 1 
      });
    }

5 Replies

danicathh
HOBBYOP

a year ago

Continuation } else if (args[2]) {
actionPost({
msg: message,
u: warnUser,
a: "warn",
r: message.content.substring(>warn ${[warnUser.id](warnUser.id)}.length),
s: 1
});
} else {
return message.react("❌");
}
} else {
return message.react("❌");
}
}
};

function msToMilliseconds(timeStr) {
const timeRegex = /^(\d+)([smhd])$/;
const match = timeStr.match(timeRegex);
if (!match) return 0;

const value = parseInt(match[1], 10);
const unit = match[2];

switch (unit) {
case 's': return value * 1000;
case 'm': return value * 60 * 1000;
case 'h': return value * 60 * 60 * 1000;
case 'd': return value * 24 * 60 * 60 * 1000;
default: return 0;
}


danicathh
HOBBYOP

a year ago

N/A


brody
EMPLOYEE

a year ago

im sorry but we cannot offer coding support here


i-jer
HOBBY

a year ago

u should ask this in .gg/djs instead


danicathh
HOBBYOP

a year ago

Sorry I didn’t know


Loading...