im wondering how i can make the repeat value and interval variables work(im new to python)
https://replit.com/@coolgamermoth/Discord-message-sender?v=1
this is a discord message sender and it asks for certain stuff like the token and api link or whatever to send certain messages at intervals, but i dont know how i could make a loop that loops at intervals for an x amount of times. anyone have any ideas? tell me if you need it to be more clear
Hey @coolgamermoth, welcome to the community!
You can use the time
module to delay sending messages like so:
from time import sleep
...
for i in range(int(repeatvalue)):
res = requests.post(link, json=payload, headers=header)
time.sleep(float(interval))
a bit confused, I assumed most operations were asynchronous…
when i tried what you did, it said this error
Traceback (most recent call last):
File "main.py", line 26, in <module>
time.sleep(float(interval))
NameError: name 'time' is not defined
but otherwise it looks like it would work(idk python so idk)
Oops
from time import sleep
...
for i in range(int(repeatvalue)):
res = requests.post(link, json=payload, headers=header)
sleep(float(interval))
tsym you are the best(i would never have figured that out on my own lol)
i have one more question, i want it to print certain things in the console if it went through or not but its not working
i changed it to this:
from time import sleep
...
for i in range(int(repeatvalue)):
res = requests.post(link, json=payload, headers=header)
print(f'''\x1b[38;5;172msuccessfully sent {message} to server! ''')
else:
print(f'''\x1b[38;5;172munsuccessfully sent {message} to server... ''')
sleep(float(interval))
idk why its wrong or how to make it right
First of all the indentation is messed up and second of all I’m not sure what the else
statement is doing there exactly. Here it is fixed
from time import sleep
...
for i in range(int(repeatvalue)):
res = requests.post(link, json=payload, headers=header)
if res.ok():
print(f'''\x1b[38;5;172msuccessfully sent {message} to server! ''')
else:
print(f'''\x1b[38;5;172munsuccessfully sent {message} to server... ''')
sleep(float(interval))
see??? idk what i am doing so thank you so much
like the ok function i didnt know about
im so sorry to waste your time, but it said this error:
Traceback (most recent call last):
File "main.py", line 27, in <module>
if res.ok():
TypeError: 'bool' object is not callable
It’s no problem, I like to help out.
Turns out it’s not a function and you’re supposed to use it without the parentheses. My bad, haven’t used it in a while (so it’s just if res.ok:
)
thank you so much for your time
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.