# Discord 自動獲取邀請碼 bot **Published by:** [lai.eth](https://paragraph.com/@lai-eth/) **Published on:** 2021-12-30 **URL:** https://paragraph.com/@lai-eth/discord-bot ## Content 簡介由於最近交易市場行情比較無聊,現在每天就跟朋友們一起刷NFT項目、完成任務拿白名單,而NFT近期也出現了不少剛好有參與到的熱點,例如MAYC、inBetweeners、Prime Ape Planet等。也因為體驗過上訴幾個NFT項目爆擊的快感,因此現在幾乎只要有收到熱度不錯的項目就會衝,而按目前的市況,幾乎每天都會有1-2個需要肝的新項目,而這些項目白單條件要求的基本上都會是聊天等級與邀請,聊天等級基本上就是在用時間與精神換取收益,至於邀請的部分,熱門項目挺常遇到的問題就是無法生成自己的邀請連結,進而導致無法完成任務,最常見的解決方法就是一直手點刷新,但實在是太浪費時間跟精神,有時候刷幾個小時都刷不到,所以才寫了這個能協助自動刷新獲取邀請碼的bot,分享出來希望能讓大家在肝白名單時稍微輕鬆一些。為了進Alpha Shark觀摩學習,剛好在反彈點附近(7.4ETH)出掉我的MAYC,哭啊dc_bot 使用説明source code""" @Auth : lai.eth @99pslai @File :get_invite.py @IDE :PyCharm """ import requests import json import time class dcBot(): def __init__(self, parent_channel=None, channel=None, Authorization=None): self.parent_channel = parent_channel self.channel = channel self.Authorization = Authorization def get_link(self): header = { "authority": "discord.com", "authorization": self.Authorization, "content-type": "application/json", "origin": "https://discord.com", "referer": "https://discord.com/channels/{}/{}".format(self.parent_channel, self.channel), "sec-fetch-dest": "empty", "sec-fetch-mode": "cors", "sec-fetch-site": "same-origin", "sec-gpc": "1", "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36" } url = "https://discord.com/api/v9/channels/{}/invites".format(self.channel) res = requests.post(url=url, headers=header, json={"validate":None,"max_age":604800,"max_uses":0,"target_type":None,"temporary":False}) result = json.loads(res.content) print(result) return result if __name__ == '__main__': dc = dcBot(parent_channel='', channel='', Authorization='') while True: try: code = dc.get_link()['code'] if code != 30016: print(code) break else: time.sleep(3) except: pass 需要取得三個參數:parent_channel, channel, Authorization先用discord網頁版登入(推薦用Google Chrome),並進入要拿邀請連結的頻道,從網址列中依序獲取 parent_channel, channel 兩個參數以SOULSHIFT為例,884812664059097129即是parent_channel,885064676566761492則是channel。下一步點擊瀏覽器右上角,選擇更多工具 > 開發人員工具,打開後在任一個頻道發送一條訊息,找到network名稱為messages的選項,複製 Headers > Request Headers 下的authorization要注意 authorization 相當於你discord帳戶的私鑰,切勿外流取得這3個參數後,用自己Google帳號登入 Google Colaboratory 運行程式碼如果你本來就有可運行Python之環境,不需要看這個步驟 點擊右下角 NEW PYTHON 3 NOTEBOOK (新增筆記本),出現如下的cell code區域,把上面給的source code貼進去。把程式碼移動到最下方 if __name__ == '__main__' 的區域(如下所示),把剛剛找到的3個參數填入第二行各個相對應的引號中。if __name__ == '__main__': dc = dcBot(parent_channel='', channel='', Authorization='') while True: try: code = dc.get_link()['code'] if code != 30016: print(code) break else: time.sleep(3) except: pass 恭喜你,再來只要點擊全部執行就可以開始運行bot運行結果程式每3秒會自動獲取一次連結(再快的話dc會有time limit),如果是顯示 {'message': 'Maximum number of invites to this server reached.', 'code': 30016},代表目前還無法要求頻道伺服器提供新的邀請連結,會一直刷新到獲取連結後程式才會自己結束邀請連結即為 https://discord.gg/42cZvaRR如果有任何問題,可以到twitter找我 @99pslai ## Publication Information - [lai.eth](https://paragraph.com/@lai-eth/): Publication homepage - [All Posts](https://paragraph.com/@lai-eth/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@lai-eth): Subscribe to updates - [Twitter](https://twitter.com/99pslai): Follow on Twitter