Closed GlamgarOnDiscord closed 1 year ago
Hey @GlamgarOnDiscord, The backup.load function takes the guild object as an argument not the guild id, you are getting this error because it can not access properties of the guild object when it got a string.
Change your code to await backup.load(backupData, guild, loadOptions);
and let me know if that works.
You can see the API surface of this package on the README
Hey @GlamgarOnDiscord, The backup.load function takes the guild object as an argument not the guild id, you are getting this error because it can not access properties of the guild object when it got a string.
Change your code to
await backup.load(backupData, guild, loadOptions);
and let me know if that works.You can see the API surface of this package on the README
Hello, sorry i am so stupid. Now say : TypeError: a.bans is not iterable at Object.K [as loadBans] (/home/runner/Backup1/node_modules/@outwalk/discord-backup/dist/index.js:1:11523) at Object.Y [as load] (/home/runner/Backup1/node_modules/@outwalk/discord-backup/dist/index.js:3:192)
Did you update the backup.create function to use guild instead of guild id as well? Ive not seen this error before. Can you provide the value of the bans
property from your backupData object?
Did you update the backup.create function to use guild instead of guild id as well? Ive not seen this error before. Can you provide the value of the
bans
property from your backupData object?
Yes, I update the script and restart the script. The value of bans it's "bans": [],
This error occurs after deleting channels.
Would you mind providing some code to reproduce this error, that way I can debug whats happening and push a fix if needed.
Would you mind providing some code to reproduce this error, that way I can debug whats happening and push a fix if needed.
,Here is load, (I use "userId' for my personal usage) :
app.post('/backup/load', async (req, res) => { try {
const { guildId, backupId, userId } = req.query;
if (!guildId) {
res.status(400).json({ error: 'guildId is missing in the parameters.' });
return;
}
if (!backupId) {
res.status(400).json({ error: 'backupId is missing in the parameters.' });
return;
}
if (!userId) {
res.status(400).json({ error: 'userId is missing in the parameters.' });
return;
}
const guild = client.guilds.cache.get(guildId);
if (!guild) {
console.error(`[❌] Guild not found: ${guildId}`.red);
return res.status(404).json({ error: 'Guild not found.' });
}
const backupID = `${backupId}_${userId}`;
const existingBackup = await backup.fetch(backupID);
if (!existingBackup) {
res.status(404).json({ error: 'Backup not found.' });
return;
}
console.log(backupID)
const backupData = await backup.fetch(backupID);
// Options de chargement de la sauvegarde
const loadOptions = {
clearGuildBeforeRestore: true,
maxMessagesPerChannel: 10,
speed: 250,
};
console.log(backupData)
// Chargez la sauvegarde sur le serveur Discord spécifié avec les options
await backup.load(backupData, guild, loadOptions);
console.log(`[✅] Backup loaded for guild with ID: ${backupID}`.green);
res.json({ success: true });
} catch (error) {
console.error([❌] Error:
, error);
res.status(500).json({ error: 'An error occurred.' });
}
});
@GlamgarOnDiscord can you provide the method to create the backup as well? Additionally unless it contains information your unable to share could you upload your backup file thats causing the error?
@GlamgarOnDiscord can you provide the method to create the backup as well? Additionally unless it contains information your unable to share could you upload your backup file thats causing the error?
Sure, 😀 :
function generateRandomCode(length) { let code = ''; const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; const charactersLength = characters.length;
for (let i = 0; i < length; i++) { const randomIndex = Math.floor(Math.random() * charactersLength); code += characters.charAt(randomIndex); }
return code; }
// Endpoint pour créer une backup app.post('/backup/create/:guildId/:userId', async (req, res) => { try { const { guildId, userId } = req.params;
if (!guildId) {
res.status(400).json({ error: 'The guildId parameter is missing.' });
return;
}
if (!userId) {
res.status(400).json({ error: 'The userId parameter is missing.' });
return;
}
// Guild exists ? :
const guild = client.guilds.cache.get(guildId);
if (!guild) {
console.error(`[❌] Guild not found: ${guildId}`.red);
return res.status(404).json({ error: 'Guild not found.' });
}
const backupId = generateRandomCode(12) + `_${userId}`;
// Options de création de la sauvegarde
const createOptions = {
backupId: backupId,
maxMessagesPerChannel: 10,
jsonSave: true,
jsonBeautify: true,
backupMembers: false,
saveImages: "base64",
speed: 250,
doNotBackup: ["bans"],
};
// Créez la sauvegarde pour le serveur Discord spécifié avec les options
const backupData = await backup.create(guild, createOptions);
console.log(`[✅] Backup created for guild with ID: ${backupId}`.green);
res.json({ success: true, backupData });
} catch (error) {
console.error([❌] Error:
, error);
res.status(500).json({ error: 'An error occurred.' });
}
});
@GlamgarOnDiscord can you provide the method to create the backup as well? Additionally unless it contains information your unable to share could you upload your backup file thats causing the error?
PS: I added ignore bans right at the end before giving it to you and it still doesn't work with or without the ignore ban.
Are you able to provide the backup file (the created json file) that is causing the error? Also after you fixed the create function did you create a new backup that also caused an error?
Are you able to provide the backup file (the created json file) that is causing the error? Also after you fixed the create function did you create a new backup that also caused an error?
@jleeson, Same error when i try with ur configuration, here it is :
`
{ "name": "Z-code dashboard", "verificationLevel": 0, "explicitContentFilter": 0, "systemChannel": null, "premiumProgressBarEnabled": false, "defaultMessageNotifications": 1, "afk": null, "widget": { "enabled": false, "channel": null }, "autoModerationRules": [], "channels": { "categories": [], "others": [] }, "roles": [ { "oldId": "1148309173407322113", "name": "new role", "color": "#000000", "hoist": false, "permissions": "0", "mentionable": false, "position": 2, "isEveryone": false }, { "oldId": "1144349513121792101", "name": "@everyone", "color": "#000000", "hoist": false, "permissions": "559623605571145", "mentionable": false, "position": 0, "isEveryone": true } ], "bans": [], "emojis": [], "members": [], "createdTimestamp": 1695225266204, "guildID": "1144349513121792101", "id": "YbYPo6O7MCzV_1098213097434529843" }
`
@GlamgarOnDiscord I tested your backup file with my own bot and it works correctly.
I believe i discovered the problem:
const backupData = await backup.fetch(backupID);
// Options de chargement de la sauvegarde
const loadOptions = {
clearGuildBeforeRestore: true,
maxMessagesPerChannel: 10,
speed: 250,
};
console.log(backupData)
// Chargez la sauvegarde sur le serveur Discord spécifié avec les options
await backup.load(backupData, guild, loadOptions);
In this code from your snippet you are passing backupData from the backup.fetch method into the load function, backupData is not the json object but rather some metadata from the backup, you can reference the actual backup data using backupData.data
the corrected code is:
const backupData = await backup.fetch(backupID);
// Options de chargement de la sauvegarde
const loadOptions = {
clearGuildBeforeRestore: true,
maxMessagesPerChannel: 10,
speed: 250,
};
console.log(backupData.data)
// Chargez la sauvegarde sur le serveur Discord spécifié avec les options
await backup.load(backupData.data, guild, loadOptions);
The fetch method is outlined in the README here, it returns an id
, size
and data
property. I have made this mistake myself, and the only reason it works this way is for compatibility with the unmaintained discord-backup package by Androz2091.
I will look into updating the load function to accept the backup object as well to prevent this in the future.
Let me know if this resolves your problem!
I went ahead and made some improvements and enabled the code to load the backup from a backupInfo object directly.
You can choose to change your code as mentioned above which will keep compatibility with the original package, or you can also go ahead and update to v0.5.6 of this package. Either way it should resolve the problem you ran into.
I went ahead and made some improvements and enabled the code to load the backup from a backupInfo object directly.
You can choose to change your code as mentioned above which will keep compatibility with the original package, or you can also go ahead and update to v0.5.6 of this package. Either way it should resolve the problem you ran into.
Thank you for the code and your explanation. Everything worked perfectly. I appreciate your help. If I encounter another issue, I’ll be sure to open a new request. Have a great day!
Great! Glad I was able to help.
Error when loading. :
Cannot read properties of undefined (reading 'cache') at x (/home/runner/Backup1/node_modules/@outwalk/discord-backup/dist/index.js:1:4228) at Object.Y [as load] (/home/runner/Backup1/node_modules/@outwalk/discord-backup/dist/index.js:3:144)
code : ` const backupData = await backup.fetch(backupID);
} catch (error) { console.error(
[❌] Error:
, error); } }); `