Skip to content

Instantly share code, notes, and snippets.

@saibalmars
Created January 3, 2022 07:09
Show Gist options
  • Save saibalmars/d0f6068c4b460feef46766f41b002eb3 to your computer and use it in GitHub Desktop.
Save saibalmars/d0f6068c4b460feef46766f41b002eb3 to your computer and use it in GitHub Desktop.
import requests
import json
import random
import time
from datetime import datetime
# You can add more than one bot if you have multiple discord accounts.
bots_setting = [
{
"name": "bot1",
"authorization": "REPLACE_ME", # Please remember to put in your discord message authorization code.
"channel_lists": [
{
"name": "Furball",
"settings": {
"channel_id": "909677800515055626",
"lottery_keyword": "**GIVEAWAY**",
"emoji_to_click": "%F0%9F%8E%89"
}
},
{
"name": "ZENAPE",
"settings": {
"channel_id": "915423377752203264",
"lottery_keyword": "**GIVEAWAY**",
"emoji_to_click": "%F0%9F%8E%89"
}
}
]
}
]
def getlist(bots_setting):
for bot in bots_setting:
header = {
"Authorization": bot["authorization"],
"Content-Type": "application/json",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36",
}
for channel in bot["channel_lists"]:
url = "https://discord.com/api/v9/channels/{}/messages?limit=10".format(channel["settings"]["channel_id"])
try:
res = requests.get(url=url, headers=header)
json_results = json.loads(res.text)
num_array = len(json_results)
for i in range(0, num_array):
try:
if channel["settings"]["lottery_keyword"] in json_results[i]["content"]:
msg_id = json_results[i]["id"]
print("-------------Lottery captured!--------------")
print("date", datetime.now())
print("id", json_results[i]["id"])
print("content", json_results[i]["content"])
print("--------------------------------------------")
url = "https://discord.com/api/v9/channels/{}/messages/{}/reactions/{}/%40me".format(
channel["settings"]["channel_id"], msg_id, channel["settings"]["emoji_to_click"])
requests.put(url=url, headers=header)
time.sleep(1)
continue
except:
pass
continue
except:
pass
continue
if __name__ == "__main__":
while True:
try:
getlist(bots_setting)
# check frequency : every 1~2 hrs by default( in seconds )
sleeptime = random.randrange(3600, 7200)
time.sleep(sleeptime)
except:
break
@simonhsu
Copy link

simonhsu commented Jan 3, 2022

!woof

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment