My program uses requests module to send and delete messages automatically, has only two functions which are sem() and dem(), program works well in my own PC, even after I converted it, but once the executable is ran by my friend in her own pc, that's when dem() stops working.
from pathlib import Path
import requests
import json
from operator import itemgetter
import time
count = 0
txt = Path(__file__).parent / "token.txt"
txt1 = Path(__file__).parent / "channel.txt"
txt2 = Path(__file__).parent / "message.txt"
txt3 = Path(__file__).parent / "timer.txt"
token = txt.read_text()
channel = txt1.read_text()
message = txt2.read_text()
timer = txt3.read_text()
payload = {
"authorization": token
}
jsondata = {
"content": message
}
ids = []
def sem():
requests.post(url=f"https://discord.com/api/v9/channels/{channel}/messages", headers=payload, json=jsondata)
def dem(message_id):
requests.delete(url=f"https://discord.com/api/v9/channels/{channel}/messages/{message_id}", headers=payload)
del(ids[-1])
evaluate()
def evaluate():
global r
global i
r = requests.get(url=f"https://discord.com/api/v9/channels/{channel}/messages", headers=payload)
i = list(json.loads(r.text))
i.sort(key=itemgetter("timestamp"))
for value in i:
if value['author']['username'] == "username":
ids.clear()
ids.append(value['id'])
evaluate()
while True:
time.sleep(int(timer))
sem()
evaluate()
dem(ids[-1])
count += 1
print("Count: "+str(count))
My program isn't just intended to be one executable, it's meant to have multiple executables, for now I only have 2 programs, one is automatic messager, and the other one is manual messager, these programs don't interact with each other at all, the point was to use one folder for 2 executables.
Here's how I converted the programs
transferred the executable through Whatsapp so that could have been an issue too, after my friend downloaded it and used it, it had a problem.
The reason my script doesn't work in the friend's pc is because evaluate() function is filtering received information from request.get for a specific username, when I was running it in my account it had my discord username, but because it can't be changed after conversion dem() couldn't find the ID with old username, and friend couldn't use it on her own discord account.
script's solution is to make "username" changeable