#How can I fix my Roblox bot overwriting cookies?
167 messages · Page 1 of 1 (latest)
This part is where it is overwriting.
await rbxbot.getCookie(cookie[i])
I just changed it to setCookie and still overwriting.
I want it to have a separate cookie for each guild.
Because I am planning on making my bot work in multiple servers.
you will have to help me understand a bit more what is wrong and what it needs to do.
you sent the while code without focusing on the part that doesn't work. I will not read the entire thing to figure out what is going on
yeah, I won't read it, the code is quite messy and 800+ lines.
you will have to pin point the issue and be more specific on what is not working
I told you what is going on
await rbxbot.setCookie(cookie)
Where cookie is retrieved from my quick.db database.
yeah and what changes?
The cookie
the cookie variable from the database?
Yes
it will overwrite if you set on it
so if you don't want that to happen, don't use set on it
well, await rbxbot.setCookie(cookie) that line cannot overwrite what is in quick.db...
which is why I need more information because what you said makes no sense whatsoever
I am retrieving the cookie from the database.
yes
let cookie = bot.db.get(ServerSetup_${guildId}.rbxcookie)
yeah that make sense
This is what my cookie is.
Do you know why it is overwriting every time the bot logs in?
no, your code doesn't seem to set anything in the database
you only have 1 set which isn't related to cookies stuff
After this is when I use the await rbxbot.setCookie(cookie)
I do have a set but that is in the Setup command.
This is in the index file.
well in the file you sent, there is nothing that could overwrite the cookies in the database
So the get is in the index file while the set is in the setup file.
So is it possible that I can only use one cookie?
you mean with the roblox library you use?
if you mean overwriting cookies because you don't await things that is different
because nothing in the file you shared should be overwriting cookies in the database. unless you do it elsewhere
Ok
Well, I think I can’t make my bot public which was my goal.
I guess people will have to host it themselves.
sorry that I wasn't able to help. but there is literally nothing that could overwrite the database in the file you sent
It keeps swapping the cookies though.
well, you do have a loop
yes because you are looping on all the cookies
It does log them separately but still.
you are not selecting a specific cookie, you also have an infite loop before
I tested it by console.log and it prints separately but it keeps swapping the cookies.
so it's like while loop into cookie loop. probably a really bad idea
I used the while loop to continue checking if the cookie exists.
So my bot doesn’t break if there isn’t a cookie.
yeah but you loop all the guilds and all the cookies for that guild. I don't what is wrong
you also for some reasons, use await and .then at the same time, which is quite confusing
Is there a way to loop through each guild individually in the index file?
well you are doing it, but the way you do it. you loop on all of them without waiting for the other one to finish
which may be what you try to refer to as the problem
Because await will wait until a cookie is set
.then as well
if you use await you don't need .then
if you use .then you don't need await
both shouldn't be used
I asked Chat GPT but can’t figure it out.
you want it to wait after each guild to then do the next one?
because right now it's not doing that
Yes?
I want it to do each guild separately.
you will need to change your forEach to for loops
forEach are not awaited which means they will all run in parallel
bot.guilds.cache.forEach(async (guild) => {
to
for (const guild of bot.guilds.cache) {
I will try that.
Do I leave my app.listen in there?
Because it might crash if it is running on the same port.
if you run it while running an other one you can just change the port for testing
This would be a no go.
that implies running a http server for each guild
yes, the app.listen shouldn't be in a loop
Ok
tbh, I wouldn't recommend even placing app.get in loops as well
if you want to make like an api and make it different for each guild, instead of changing the port. you should ask for a guildid in the get.
https://expressjs.com/en/guide/routing.html
app.get('/users/:userId/books/:bookId', (req, res) => {
res.send(req.params)
})
Route path: /users/:userId/books/:bookId
Request URL: http://localhost:3000/users/34/books/8989
req.params: { "userId": "34", "bookId": "8989" }```
with those params, you can like get cookies for a certain guild and do what is needed
Ok, thanks for the info
that probably is the problem actually, the problem was probably that it changed guild or changed cookies when you did a request to it because all guilds used the same endpoint. which made it completely random when you did requests
this, is problably the problem
right now, if you do a request to the api, you don't know which guild or which cookie you will get. I am not too sure what you are trying to do, but it's not a good design
you can't use two at the same time
Oh
the way the roblox libary works, it's one after the other
let me check the source code of the roblox script
Ok
I just want it to work in multiple servers.
Chat gpt tried to tell me to use const rbxbot = new noblox({ cookie: cookie, groupid: groupid, }) but it said noblox isn't a constructor.
If it is possible to run multiple Roblox instances in one project I would like to know. Thanks!
from what I can see, the setCookies method doesn't log in the user
it just gets the current user with the cookies passed in
exports.func = async function (args) {
// verify it
if (!args.cookie.toLowerCase().includes('warning:-')) {
console.error('Warning: No Roblox warning detected in provided cookie. Ensure you include the entire .ROBLOSECURITY warning.')
}
if (args.validate === false) {
options.jar.session = args.cookie
return false
}
try {
const res = await getCurrentUser({ jar: { session: args.cookie } })
options.jar.session = args.cookie
return res
} catch (error) {
console.error('Failed to validate cookie: Are you sure the cookie is valid?\nEnsure you include the full cookie, including warning text.')
throw new Error(error)
}
}```
it just getCurrentUser
it doesn't log in
What part logs in?
getCurrentUser function
exports.func = async function (args) {
const jar = args.jar
const option = args.option
const httpOpt = {
url: '//www.roblox.com/mobileapi/userinfo',
options: {
resolveWithFullResponse: true,
method: 'GET',
followRedirect: false,
jar: jar
}
}
const res = await http(httpOpt)
if (res.statusCode !== 200) {
throw new Error('You are not logged in.')
}
const json = JSON.parse(res.body)
if (!option) {
return json
}
const searchKey = Object.keys(json).filter((key) => {
return option.toLowerCase() === key.toLowerCase()
})[0]
return json[searchKey]
}```
this only request once with the cookies
which means that using other method from the roblox lib after that won't magically be connected to the account
if you need multiple you will have to pass cookies to each of the functions
and some functions you actually can't
you will have to do them one by one
I thought the for loops will do one by one
the for loop should but you use a mixture of .then and await
so I cannot tell if it will wait or not
only await makes the code pause while .then continues running stuff after
also the error you posted doesn't come from the index file
It comes from this?
const {
Client,
Message,
EmbedBuilder,
CommandInteraction,
MessageActionRow,
MessageButton,
} = require('discord.js')
const noblox = require('noblox.js')
require('dotenv').config();
const { SlashCommandBuilder } = require('@discordjs/builders')
module.exports = {
name: 'Shout',
description: 'Send a Shout to the Roblox Group!',
data: new SlashCommandBuilder()
.setName('shout')
.setDescription('Send a Shout to the Roblox Group!')
.addStringOption(option =>
option.setName('message')
.setDescription('Send a Shout message to the Roblox Group!').setRequired(true)
),
/**
*
* @param {Client} bot
* @param {Message} message
* @param {String[]} args
*/
async execute(bot, message, args) {},
/**
*
* @param {Client} bot
* @param {CommandInteraction} interaction
*/
async slashexecute(bot, interaction) {
const shoutmessage = interaction.options.getString('message');
let cookie = bot.db.get(`ServerSetup_${interaction.guild.id}.rblxcookie`);
let groupid = bot.db.get(`ServerSetup_${interaction.guild.id}.rblxgroupid`);
let groupshout = bot.db.get(`ServerSetup_${interaction.guild.id}.rblxshout`);
let activity = bot.db.get(`ServerSetup_${interaction.guild.id}.botactivity`);
let minrank = bot.db.get(`ServerSetup_${interaction.guild.id}.minimumrank`);
let logs = bot.db.get(`ServerSetup_${interaction.guild.id}.botlogs`);
await interaction.deferReply({ephemeral: true})
try {
if (!(cookie && groupid && groupshout && activity && minrank && logs)) return interaction.editReply({ content: `**Failed!** | Please use the **/setup** command to setup the bot for this server!`});
console.log()
noblox.shout(groupid, shoutmessage)
interaction.editReply({ content: `Successfully Posted Shout to the Roblox Group!`,
})
let avatar = await noblox.getPlayerThumbnail(`${await noblox.getCurrentUser("UserId")}`, "48x48", "png", true, "headshot");
let avatarurl = avatar[0].imageUrl;
let embed = new EmbedBuilder()
.setTitle(`**Rank Management!**`)
.setDescription(`**Username:**\n${await noblox.getCurrentUser("UserName")}\n**UserId:**\n${await noblox.getCurrentUser("UserId")}\n**Rank Management Type:**\nShout\n**Shout Message:**\n${shoutmessage}\n**Command Used By:**`)
.setColor('Green')
.setAuthor({ name: `${await noblox.getCurrentUser("UserName")}`, iconURL: avatarurl })
.setFooter({ text: interaction.member.user.username, iconURL: interaction.member.user.displayAvatarURL() })
.setTimestamp(Date.now());
interaction.channel.send({ embeds: [embed] })
} catch (error) {
interaction.editReply({ content: `Failed to Post Shout to Roblox Group!`,
})
console.log(error.message)
}
},
}
I will not help more than this, because I noticed the bot you are trying to make seems really fishy.
verifying multiple cookies in a loop.. sounds something not good to me
This is the shout file
What is phishy about it?
the use of multiple cookies
which could be for unauthorized access to some accounds
So I want people to set it up with their own server.
Uh no?
It's not a cookie logger.
It is used for multiple servers.
So they can use their own Roblox bot.
I was thinking of using my Roblox bot to join their groups but there is a limit on how many groups it can join.
sure,
now if we check the file you just sent.
noblox.shout(groupid, shoutmessage)
this is used
now, when do you connect the user ?
shout seems to require an account but you never connect the user beforehand
It works for one of the bots but not the other with that same command for some reason.
yeah because the currently logged in user is totally random
you have like an a loop that connects every account in the index
Oh
and it can only have 1 connected account at the time
Well, I want it to run multiple instances.
of the bot
So it can use more than 1 account
It will be quite difficult to achive this, and hopefully you have a good pc/vps
I am using Digital Ocean and VS Code
My SSH is Bitvise
All the code files are on the Cloud.
ie. Remote files.
the code editor doesn't matter, so is ssh.
also digital ocean has multiple droplets I think it's called, of different specs
I got a high one
if you want to use shout, you won't be able to pass in cookies so you will have to connect before.
what you can do is connect the account before it uses shout.
instead of connecting all accounts in the index file.
if you go for multiple instance, I won't help with this, it will take a lot of time for me to explain everything