├── README.md └── discord-chat.py /README.md: -------------------------------------------------------------------------------- 1 | 2 | 最新更新⬇️⬇️ 3 | 4 | ## 想玩NFT,强烈欢迎加入 我们的nft群。玩NFT才赚钱 谁TM写代码。➕wechat:zxmeng1999 5 | 6 | ## 使用下面🔗在线运行,有疑问可以加我微信 zxmeng1999 7 | https://colab.research.google.com/drive/1na6TrIL0ntj4IHj2sIZhTPUKO4NWiArt?usp=sharing 8 | 9 | 视频教程在:YouTube :https://www.youtube.com/watch?v=XQfhTPm_FJo (感谢支持,多多点赞) 10 | 11 | 作者 🔗:https://linktr.ee/erwaplayblockchain (更多内容) 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /discord-chat.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | @Time : 2021/10/3 19:18 4 | @Auth : WX:zxmeng1999 youtuber:二娃玩转区块链 5 | @IDE :PyCharm 6 | 7 | """ 8 | import requests,re,json,random,time 9 | 10 | 11 | authorization_list = [] 12 | dict_chanel_list = {} 13 | 14 | def basic_context(): 15 | context_list = [ 16 | "great!","hello bro","let's go !","to the moon!","gm","couldn't sleep","have a good day","gm bro","!!!!","hello all","welcome everyone","thanks" 17 | ] 18 | text = random.choice(context_list) 19 | return text 20 | 21 | def get_context(auth,chanel_id): 22 | # 此方法暂时无法使用 23 | # discord 官方更新了 cloudflare 拦截请求 此方法暂时无法使用 24 | # 有精力的小伙伴,可以试试 看下请求解决下 25 | print(auth, chanel_id) 26 | headr = { 27 | "Authorization": auth, 28 | "Content-Type": "application/json", 29 | "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" 30 | } 31 | # chanel_id = random.choice(chanel_list) 32 | url = "https://discord.com/api/v9/channels/{}/messages?limit=100".format(chanel_id) 33 | 34 | res = requests.get(url=url, headers=headr) 35 | # 由于官方更新了 36 | 37 | result = json.loads(res.content) 38 | result_list = [] 39 | for context in result: 40 | if ('<') not in context['content'] : 41 | if ('@') not in context['content'] : 42 | if ('http') not in context['content']: 43 | if ('?') not in context['content']: 44 | result_list.append(context['content']) 45 | 46 | return random.choice(result_list) 47 | 48 | def chat(): 49 | 50 | for key in range(len(authorization_list)): 51 | authorization = authorization_list[key] 52 | header = { 53 | "Authorization":authorization, 54 | "Content-Type":"application/json", 55 | "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" 56 | } 57 | for chanel_key in range(len(dict_chanel_list[authorization])): 58 | chanel_id = dict_chanel_list[authorization][chanel_key] 59 | print("用户:"+ authorization,"id"+ chanel_id,chanel_key ) 60 | time.sleep(10) 61 | msg = { 62 | "content": basic_context(), # 如果解决了cloudflare 可以换成 get_context() 63 | "nonce": "82329451214{}33232234".format(random.randrange(0, 1000)), 64 | "tts": False 65 | } 66 | print(msg) 67 | url = 'https://discord.com/api/v9/channels/{}/messages'.format(chanel_id) 68 | try: 69 | res = requests.post(url=url, headers=header, data=json.dumps(msg)) 70 | print(res) 71 | 72 | except: 73 | pass 74 | continue 75 | time.sleep(random.randrange(30,50)) 76 | 77 | 78 | if __name__ == '__main__': 79 | while True: 80 | try: 81 | chat() 82 | sleeptime = random.randrange(120, 180) 83 | time.sleep(sleeptime) 84 | except: 85 | pass 86 | continue 87 | 88 | 89 | --------------------------------------------------------------------------------