$setGlobalUserObjectVar
Changes the value of a given global user variable object.
Usage
$setGlobalUserObjectVar[varname;property;value;userID?;table?]
Parameters
varname
- The variable name.
property
- The name of the property.
value
- The new variable property value.
userID?
- The user ID. (Optional)
table?
- Variable table. (Optional)
Source Code
module.exports = {
name: "$setGlobalUserObjectVar",
type: "djs",
code: async d => {
const data = d.util.aoiFunc(d);
let [varname, property, value, userID = d.author?.id, table = d.client.db.tables[0]] = data.inside.splits;
varname = varname.addBrackets();
if (!d.client.variableManager.has(varname.addBrackets(), table)) {
return d.aoiError.fnError(d, "custom", {}, `Variable ${varname.addBrackets()} Not Found!`);
}
let variable = d.client.variableManager.get(varname, table);
if (!variable.checkType(value)) {
console.log(value)
return d.aoiError.fnError(d, "custom", { inside: data.inside }, `Variable "${varname.addBrackets()}" Needs Value Of Type "${variable.type}". Provided Wrong Type In`);
}
if (!typeof variable === 'object') {
console.log(variable)
return d.aoiError.fnError(d, 'custom', {}, `Variable "${varname}" Not Object`);
}
variable = variableValue = variable.value || variable.default;
if (!variable.hasOwnProperty(property)) {
console.log(property)
return d.aoiError.fnError(d, 'custom', {}, `Property "${property}" Not Found`);
}
variable[property] = value = d.client.variableManager.parseData(value, variable.type);
try {
await d.client.db.set(table, varname.addBrackets(), userID, variable);
} catch (e) {
d.aoiError.fnError(d, "custom", {}, `Failed To Set Value To The Variable: "${varname.addBrackets()}" With Reason: ${e}`);
}
return {
code: d.util.setCode(data)
}
}
}
What is an object variable?
An object variable is a variable that holds a reference to an object. Objects are collections of key-value pairs, where keys are strings (or symbols), and values can be any data type, including other objects or primitive values like strings or numbers. This type of variable can be created through this method:
<AoiClient>.variables({
varname: {
key: value
}
});