#bot went nuts

105 messages · Page 1 of 1 (latest)

marsh abyss
#

Bot suddenly went nuts after pc reboot

##
##@client.listen()
##async def on_message(message):
##    userid = f"['{message.author.id}']"
##    with open("whitelist.txt") as whitelist:
##        whitelist = whitelist.read().split()
##        if message.author == client.user:
##            return
##        if message.channel.id == 978472349827485716:
##            return
##        if userid not in whitelist:
##            msg = message.content
##            with open("BadWords.txt") as BadWords:
##                BadWordsList = BadWords.read().split(':') #it'll split by space, unless you pass in a custom split condition like '/n' or something
##                for word in BadWordsList:
##                    if word in message.content:
##                        await message.delete()
##                        await message.channel.send("Dont say that! contact Dr. Jack Bright#4243 if this made no sense")
##                        print(message.author,message.content)
##                        return
``` suddenly, it stopped working right, and started going haywire....no clue what happened but I had to comment out the code
#

It was literally fine a little while ago

trim reef
#

How many servers is the bot in?

#

You probably got like half a thousand on_message events firing at it

tawny plover
#

You should define "haywire"

marsh abyss
#

Very haywire

#

As in random stuff would trigger it, and it'd delete the message and say "
Don't say that!"

#

Mostly links

#

So, it only had about 3 triggers per second....the effect was rather small, thankfully

#

Lmfao, even this AI said it's bad.......

#

It looks like BadWordsList is being split by ':', but it's not clear if this is intended or if it will cause any problems. It might be better to split the list by newline characters ('\n') or whitespace characters (' ') instead.
The whitelist variable is being overwritten when it is read from the file, which means that any values that were previously stored in the whitelist variable will be lost. It might be better to use a different variable name for the whitelist that is read from the file.
The userid variable is being defined as a string, but it looks like it should be an integer. If message.author.id is an integer, then userid should be defined as userid = message.author.id instead.
The if message.channel.id == 978472349827485716: line seems unnecessary, since it just immediately returns without doing anything. It might be better to remove this line if it's not serving any purpose.
It's not clear where the client variable is defined or what it is used for. If this variable is necessary for the code to work correctly, then it should be defined before it is used.
Overall, the code seems to be trying to filter out messages that contain certain words and delete them if they are not from a user on the whitelist. However, there are a few issues with the implementation that could cause the code to behave unexpectedly.```
#

@client.event
async def on_message(message):
    # Convert the user ID to an integer
    userid = f"['{message.author.id}]'"

    # Load the list of users on the whitelist from a file
    with open("whitelist.txt") as f:
        whitelist = [int(x) for x in f.read().split()]

    # Ignore messages from the bot itself
    if message.author == client.user:
        return

    # Ignore messages from the specified channel
    if message.channel.id == 978472349827485716:
        return

    # Check if the user is on the whitelist
    if userid not in whitelist:
        # Load the list of bad words from a file
        with open("BadWords.txt") as f:
            bad_words = f.read().split(':')

        # Check if the message contains any bad words
        for word in bad_words:
            if word in message.content:
                # Delete the message if it contains a bad word
                await message.delete()
                # Send a warning message to the channel
                await message.channel.send("Don't say that! Contact Dr. Jack Bright#4243 if this made no sense.")
                # Print the author and content of the deleted message
                print(message.author, message.content)
                # Stop processing the current message
                return
``` how would this AI fixed code work, I'm curious
#

@trim reef

trim reef
#

Looks like Python

#

Not sure what's up with the userid var

marsh abyss
#

Originally it's for premium users, so the bot ignores them when they sailor talk

#

Though, with automod picking up popularity, I may just flat out remove the filter alltogether

#

Though I do see a mistake in it

#

@client.event
async def on_message(message):
    # Convert the user ID to an integer
    userid = f"['{message.author.id}']"

    # Load the list of users on the whitelist from a file
    with open("whitelist.txt") as f:
        whitelist = [int(x) for x in f.read().split()]

    # Ignore messages from the bot itself
    if message.author == client.user:
        return

    # Ignore messages from the specified channel
    if message.channel.id == 978472349827485716:
        return

    # Check if the user is on the whitelist
    if userid not in whitelist:
        # Load the list of bad words from a file
        with open("BadWords.txt") as f:
            bad_words = f.read().split(':')

        # Check if the message contains any bad words
        for word in bad_words:
            if word in message.content:
                # Delete the message if it contains a bad word
                await message.delete()
                # Send a warning message to the channel
                await message.channel.send("Don't say that! Contact Dr. Jack Bright#4243 if this made no sense.")
                # Print the author and content of the deleted message
                print(message.author, message.content)
                # Stop processing the current message
                return
#

I'm reading user ID like this ['990617718308888646'] ['611946907538817055'] ['922904006739767386'] ['777106954676994049'] ['1032887528484782110'] ['571516713389260820'] ['933587784218853386'] ['1042556259456536618'] ['612378014000611328'] ['1028331453798432820'] ['916041608288407622'] ['1040023546048544799'] ['950450141788266546'] ['924291221864734810'] ['1026198618824245392']

marsh abyss
#
@client.listen()
async def on_message(message):
    userid = f"['{message.author.id}']"
    with open("whitelist.txt") as f:
        whitelist = f.read().split()
        if message.author == client.user:
            return
        if message.channel.id == 978472349827485716:
            return
        if userid not in whitelist:
            with open("BadWords.txt") as f:
                bad_words = f.read().split(':')
                for word in bad_words:
                    if word in message.content:
                        await message.delete()
                        await message.channel.send("Dont say that! contact Dr. Jack Bright#4243 if this made no sense")
                        print(message.author, message.content)
                        return``` specified to the AI not to change the `userid` variable
trim reef
#

Boot up another bot to test?

#

Seems to be functional code Shrug

marsh abyss
#

Hearing that from a better programmer....that's impressive...i'm geeking out so hard right now😂

#

It does work, but the premium detection doesn't work

#

All in all, that's impressive though

trim reef
#

You're comparing a list to a string that's formatted to look slightly like a list

#

Chill.

marsh abyss
#

Keyboard went nuts

#

My bad

trim reef
#

...

marsh abyss
#

I have sticky buttons....

#

Just had to smack it

#

Oh wow that ....did...alot

trim reef
#

Maybe clean your keyboard more than the time you pull it out of the packaging?

marsh abyss
#

It's just cheap, I need to sand the keys

marsh abyss
#

["['796544135606697997']", "['952479585868591145']", "['850757557048180737']", "['811857616778952714']", "['412817721114361866']", "['373662017375961098']", "['838286198572580904']"] I need to not print it like this, and using the newline didn't help

trim reef
#

From what code is that?

#

And which variable?

marsh abyss
#

So, the IDs are kept stored like this: ['990617718308888646'] ['611946907538817055'] ['922904006739767386'] ['777106954676994049'] ['1032887528484782110'] ['571516713389260820'] ['933587784218853386'] ['1042556259456536618'] ['612378014000611328'] ['1028331453798432820'] ['916041608288407622'] ['1040023546048544799'] ['950450141788266546'] ['924291221864734810'] ['1026198618824245392']

#

So, I need to modify the code to read it as it is

#

Fortunately, once I learn how, I'll always know how

trim reef
#

Maybe change that around to not be an f-string?

#

Or have the f-string inside the list

marsh abyss
#

It has to pick up the current userid and wrap it like ['userid']

trim reef
#

How would you use a string inside a list?

marsh abyss
#

For everything else, I can send another piece of working code

trim reef
#

What

marsh abyss
#
@client.listen()
async def on_message(message):
    if isinstance(message.channel, discord.channel.DMChannel):
        pass
    else:
        server = f"['{message.guild.id}']"
        with open("premium_servers.txt") as premium_servers:
            premium = premium_servers.read().split()
            #premium = f.read()
            #print(server)
            if server in premium:
                for attachment in message.attachments:
                    #print(message.content)    
                    code = message.attachments[0].url
                    #print(code)
                    respond = requests.get(code)
                    filename = Image.open(BytesIO(respond.content))


                    im = grab()

                    for qrcode in decode(filename):
                        qr_str = str(qrcode.data)
                        qr_str = qr_str[2:][:-1]
                        print(qr_str)
                        if "https://discord.com/ra/" in f"{qr_str}":
                            await message.delete()
                            await message.channel.send(f'bruh, we are not doing QR code scams {message.author.mention}')
                            await message.author.ban()
                            with open('instaban.txt', 'a') as f:
                                f.write(f"\n['{message.author.id}']")
                            os.system("cls")
``` this uses the same list type
trim reef
#

How would you use an f-string for a list value?

marsh abyss
#

I'm running low on caffine

trim reef
#

['somestring']

#

How would you convert that to an f-string?

#

Without messing with the brackets

#

Or adding anything outside them

marsh abyss
#
 f"['{message.guild.id}']"```
trim reef
#

'somestring' What about this?

marsh abyss
#
 f"'{message.guild.id}'"```
trim reef
#

Are you just guessing now?

#

Try the examples I gave

marsh abyss
#

I'm not understanding what you mean...

trim reef
#

Edit this: 'something' to be an f-string

#

Don't change what's in it, just change it to an f-string

#

Little tip: F-strings don't need double quotes

marsh abyss
#

...I'm not understanding

trim reef
#

'something' to an f-string, right?

#

You add the f to it?

#

How would that look like if you did that?

marsh abyss
#

You mean if something was a variable?

trim reef
#

No, literal 'something'-string, into an f-string

#

The something doesn't matter in this case

#

It's a placeholder

#

Trying to get you to think and figure it out yourself instead of giving you the answer just outright

marsh abyss
#
string = 'something'
print(f"{string}")
``` something like this
trim reef
#

No

#

You add the f in front, right?

marsh abyss
#

Yes

trim reef
#

So, what would 'something' be, if that was the value of a var, and you wanted the value to be an f-string

#

I can type it like this:
var = 'something'

#

Now, without adding any new variables or anything, change that line to be an f-string instead

#

You can do that with a single f

#

Where would you place that?

marsh abyss
#

Var = f'something'

trim reef
#

There you go

#

Now how would you make that into a list?

marsh abyss
#

I need to load it from my text file

trim reef
#

.....

#

Kinda missed what I was trying to say

marsh abyss
#

I'm sorry, I'm a visual learner

trim reef
marsh abyss
#

Yes

trim reef
#

Now, using the previous example I got you to type out

#

How would you modify that, to be a list ([...]), with an f-string inside?

marsh abyss
#

Sorry I've got 3 people that refuse to leave me alone

trim reef
#

f"['{message.guild.id}']" doesn't work, it's an f-string wrapping the list

You need to have the brackets at the very end on both sides, not quotes

#

Change the string inside to be an f-string

#

Done

marsh abyss
#

It's a mediocre feature, and it's not important right now....I'm forced to have to wait until people get out of my face, because I cannot think

trim reef
#

.......

#

[f'...']

marsh abyss
#

Sorry, I had to shut off the breaker to get 5 people out of my room and leave me alone

#

I'm just forgoing the whole bad word filter, and just sticking with the anti QR code scam for chat moderation

marsh abyss
#

This can be deleted, I'm done with it, i have a more pressing question about discord py slash commands