Skip to content

Commit

Permalink
add ability for multiple channels
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGamer3514 committed Jul 30, 2023
0 parents commit 4ab4100
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 0 deletions.
10 changes: 10 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Config": [
{
"token": "",
"channelids": [channelids],
"message": "hello! this message is sent every 2 mins :)",
"web": "true"
}
]
}
31 changes: 31 additions & 0 deletions keepalive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os
try:
import flask
except ImportError:
print("Flask Not Found...\nInstalling...")
os.system("pip install flask")
print("Flask Installed")

from flask import Flask
from threading import Thread
import random


app = Flask('')

@app.route('/')
def home():
return 'Sub To The Gamer3514'

def run():
app.run(
host='0.0.0.0',
port=random.randint(2000,9000)
)

def keep_alive():
'''
Creates and starts new thread that runs the function run.
'''
t = Thread(target=run)
t.start()
58 changes: 58 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#Import Modules
from http.client import HTTPSConnection
from sys import stderr
from json import dumps
from time import sleep
import json
#Load Config
with open('./config.json') as f:
data = json.load(f)
for c in data['Config']:
print('Loading...')
channelids = c['channelids'] #modify this in config.json
token = c['token'] #modify this in config.json
message = c['message'] #modify this in config.json
web = c['web'] #modify this in config.json
header_data = {
"content-type": "application/json",
"user-agent": "discordapp.com",
"authorization": token
}

def get_connection():
return HTTPSConnection("discordapp.com", 443)

def send_message(conn, channel_id, message_data):
try:
conn.request("POST", f"/api/v7/channels/{channel_id}/messages", message_data, header_data)
resp = conn.getresponse()

if 199 < resp.status < 300:
print("Message Sent")
pass

else:
stderr.write(f"HTTP {resp.status}: {resp.reason}\n")
pass

except:
stderr.write("Error\n")

def main():
message_data = {
"content": message,
"tts": "false"
}
for channelid in channelids:
send_message(get_connection(), channelid, dumps(message_data))
#Keep Alive
if web == "true":
from keepalive import keep_alive
keep_alive()
else:
print("Web Server Disabled")
#Start The Sender
if __name__ == '__main__':
while True:
main()
sleep(120) #How often the message should be sent (in seconds), every 1 hour = 3600
12 changes: 12 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# AutoSendDiscordMessage
A simple Python code to send a message with your discord account every set amount of time, without having to be online.

- Support: https://discord.gg/3qvpkgWSbF
# Setup
1. Fill Out The Config In `config.json`
2. Run `python main.py`
3. Done! If you want to change more then that is fine!
# How To Get Discord Token
1. Go on [Discord Web](https://discord.com/app) and open [Console](https://www.youtube.com/watch?v=nFFKnWw-_Ys&ab_channel=MDTechVideos)
2. In console paste the following command: `webpackChunkdiscord_app.push([[""],{},req=>copy(Object.values(req.c).find(x => x?.exports?.default?.getToken).exports.default.getToken())])`
3. Now your token should be coppied to your clipboard!

0 comments on commit 4ab4100

Please sign in to comment.