Skip to content

Commit

Permalink
fix($createThread): invalid parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Faf4a committed Nov 29, 2023
1 parent f982707 commit 5d2d887
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/functions/guild/createThread.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
module.exports = async d => {
const {code} = d.command;
const inside = d.unpack();
const err = d.inside(inside);
if (err) return d.error(err);
const data = d.util.aoiFunc(d);
const { code } = d.command;
if (data.err) return d.error(data.err);

let [channelID, name, archive = "MAX", type = "public", startMessage, returnID = "false"] = inside.splits;
let [channelID, name, archive = "MAX", type = "public", startMessage, returnID = "false"] = data.inside.splits;

const channel = await d.util.getChannel(d, channelID);
if (!channel) return d.aoiError.fnError(d, "channel", {inside});
if (!channel) return d.aoiError.fnError(d, "channel", { inside: data.inside });

type = d.util.threadTypes[type];
if (!type) return d.aoiError.fnError(d, "custom", {inside}, "Invalid Type Provided In");
if (!["60", "1440", "4320", "10080", "MAX"].includes(archive.toUpperCase())) d.aoiError.fnError(d, "custom", {inside}, "Invalid Archive Duration Provided In");
if (!type) return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Invalid Type Provided In");
if (!["60", "1440", "4320", "10080", "MAX"].includes(archive.toUpperCase())) return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Archive Duration Provided In");

const result = await channel.threads.create({
name,
autoArchiveDuration: archive,
autoArchiveDuration: archive.toUpperCase().replace("MAX", "10080"),
type,
startMessage: startMessage?.trim() === "" ? undefined : startMessage
}).catch(e => {
d.aoiError.fnError(d, "custom", {}, "Failed To Create Thread With Reason: " + e);
return d.aoiError.fnError(d, "custom", {}, "Failed To Create Thread With Reason: " + e);
});

data.result = returnID === "true" ? result?.id : undefined;

return {
code: d.util.setCode({function: d.func, code, inside, result: returnID === "true" ? result?.id : ""})
code: d.util.setCode(data)
}
}

0 comments on commit 5d2d887

Please sign in to comment.