Skip to content

Instantly share code, notes, and snippets.

@danielgxm
Last active February 18, 2024 08:27
Show Gist options
  • Save danielgxm/284ca373c7066b958fdb6ee11fde1770 to your computer and use it in GitHub Desktop.
Save danielgxm/284ca373c7066b958fdb6ee11fde1770 to your computer and use it in GitHub Desktop.
discord自动打卡机器人
# -*- coding: utf-8 -*-
# discord早晚打卡机器人
"""
@Time : 2021/10/3 19:18
@Auth : d1rrick DanielGao.eth
@File :autochat.py
@IDE :vscode
"""
import requests
import json
import random
import datetime
import time
import re
def chat(content):
# 频道ID(chanel_id),把需要打卡的频道ID都加到这个数组里。实现一键打卡。
chanel_list = ['891977019544457260', '912984706830716968',
'899999888916484156', '847294242623979550', '891912185041793074','899598848102637589']
# 访问凭据
authorization = 'OXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXY'
header = {
"Authorization": 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 chanel_id in chanel_list:
msg = {
"content": content,
"nonce": "82329451214{}33232234".format(random.randrange(0, 1000)),
"tts": False
}
url = 'https://discord.com/api/v9/channels/{}/messages'.format(
chanel_id)
try:
res = requests.post(url=url, headers=header,
data=json.dumps(msg))
print(res.content)
except:
pass
# 取30秒到50之间的一个随机数,作为循环的间隔时间。
time.sleep(random.randrange(30, 50))
if __name__ == '__main__':
while True:
try:
print('start')
# 获取现在的时间
hour = datetime.datetime.now().hour
print(hour)
if hour < 18:
# 早打卡
chat("gm")
elif hour >= 18:
# 晚于18点,晚打卡
chat("gn")
# 每六个小时运行一次
time.sleep(21600)
except:
pass
continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment