#How can I fix my Roblox bot overwriting cookies?

167 messages · Page 1 of 1 (latest)

fathom plaza
#

So the issue is that I am getting the cookies from the quick.db database and setting them but when the bot logs in with those cookies it overwrites one or the other.

#

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.

minor marlin
#

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

fathom plaza
#

await rbxbot.setCookie(cookie)

#

Where cookie is retrieved from my quick.db database.

minor marlin
#

yeah and what changes?

fathom plaza
#

The cookie

minor marlin
#

the cookie variable from the database?

fathom plaza
#

Yes

minor marlin
#

it will overwrite if you set on it

#

so if you don't want that to happen, don't use set on it

fathom plaza
#

When I try to login with the cookie yes

#

So do I use push instead?

minor marlin
#

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

fathom plaza
#

I am retrieving the cookie from the database.

minor marlin
#

yes

fathom plaza
#

let cookie = bot.db.get(ServerSetup_${guildId}.rbxcookie)

minor marlin
#

yeah that make sense

fathom plaza
#

This is what my cookie is.

#

Do you know why it is overwriting every time the bot logs in?

minor marlin
#

no, your code doesn't seem to set anything in the database

#

you only have 1 set which isn't related to cookies stuff

fathom plaza
#

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.

minor marlin
#

well in the file you sent, there is nothing that could overwrite the cookies in the database

fathom plaza
#

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?

minor marlin
#

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

fathom plaza
#

Ok

#

Well, I think I can’t make my bot public which was my goal.

#

I guess people will have to host it themselves.

minor marlin
#

sorry that I wasn't able to help. but there is literally nothing that could overwrite the database in the file you sent

fathom plaza
#

It keeps swapping the cookies though.

minor marlin
#

well, you do have a loop

fathom plaza
#

Yes

#

But still getting every cookie instead of the one for that guild.

minor marlin
#

yes because you are looping on all the cookies

fathom plaza
#

It does log them separately but still.

minor marlin
#

you are not selecting a specific cookie, you also have an infite loop before

fathom plaza
#

I tested it by console.log and it prints separately but it keeps swapping the cookies.

minor marlin
#

so it's like while loop into cookie loop. probably a really bad idea

fathom plaza
#

I used the while loop to continue checking if the cookie exists.

#

So my bot doesn’t break if there isn’t a cookie.

minor marlin
#

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

fathom plaza
#

Is there a way to loop through each guild individually in the index file?

minor marlin
#

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

fathom plaza
minor marlin
#

.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

fathom plaza
minor marlin
#

you want it to wait after each guild to then do the next one?

#

because right now it's not doing that

fathom plaza
#

I want it to do each guild separately.

minor marlin
#

you will need to change your forEach to for loops

#

forEach are not awaited which means they will all run in parallel

fathom plaza
#

Example?

#

I didn’t know what to use either map foreach or what.

minor marlin
#
bot.guilds.cache.forEach(async (guild) => {

to

for (const guild of bot.guilds.cache) {
fathom plaza
#

Do I leave my app.listen in there?

#

Because it might crash if it is running on the same port.

minor marlin
#

if you run it while running an other one you can just change the port for testing

fathom plaza
#

Can I make the port change for each guild?

#

Without manually changing it?

minor marlin
#

This would be a no go.
that implies running a http server for each guild

fathom plaza
#

Oh

#

So I should keep them all on the same port?

minor marlin
#

yes, the app.listen shouldn't be in a loop

fathom plaza
#

Ok

minor marlin
#

tbh, I wouldn't recommend even placing app.get in loops as well

fathom plaza
#

Oh thanks

#

I was about to ask that too

#

Because I do have app.gets

minor marlin
#

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

fathom plaza
#

Ok, thanks for the info

minor marlin
#

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

fathom plaza
#

I am testing the for loop you gave me right now

#

It still didn't work.

minor marlin
fathom plaza
minor marlin
#

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

fathom plaza
#

It is saying they are both logged in

#

But only one is working

minor marlin
#

you can't use two at the same time

fathom plaza
#

Oh

minor marlin
#

the way the roblox libary works, it's one after the other

fathom plaza
#

Is there a way I can do both at the same time?

#

Or is that a no?

minor marlin
#

let me check the source code of the roblox script

fathom plaza
#

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!

minor marlin
#

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

fathom plaza
#

It doesn't?

#

I thought setCookie logs in the Roblox bot.

#

So what do I do then?

minor marlin
#
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

fathom plaza
#

What part logs in?

minor marlin
#

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

fathom plaza
#

Ok

#

Is there a way I could make it log in with multiple cookies?

minor marlin
#

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

fathom plaza
#

I thought the for loops will do one by one

minor marlin
#

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

fathom plaza
#

Ok

#

Let me try removing await

minor marlin
#

also the error you posted doesn't come from the index file

fathom plaza
#

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)
            }
        },
}
minor marlin
#

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

fathom plaza
#

This is the shout file

minor marlin
#

the use of multiple cookies

fathom plaza
#

How?

#

It is supposed to be a multi server bot.

minor marlin
#

which could be for unauthorized access to some accounds

fathom plaza
#

So I want people to set it up with their own server.

fathom plaza
#

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.

minor marlin
#

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

fathom plaza
#

It works for one of the bots but not the other with that same command for some reason.

minor marlin
#

yeah because the currently logged in user is totally random

#

you have like an a loop that connects every account in the index

fathom plaza
#

Oh

minor marlin
#

and it can only have 1 connected account at the time

fathom plaza
#

Well, I want it to run multiple instances.

#

of the bot

#

So it can use more than 1 account

minor marlin
#

It will be quite difficult to achive this, and hopefully you have a good pc/vps

fathom plaza
#

I am using Digital Ocean and VS Code

#

My SSH is Bitvise

#

All the code files are on the Cloud.

#

ie. Remote files.

minor marlin
#

the code editor doesn't matter, so is ssh.
also digital ocean has multiple droplets I think it's called, of different specs

fathom plaza
#

I got a high one

minor marlin
#

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

fathom plaza
#

I think I change my mind. I will make people host the bot themselves.

#

Because this is very difficult. I can't even get specific guild ids in the index file.

minor marlin
#

you could try the login on command approach instead

#

you do have the guild id there