Skip to content

Instantly share code, notes, and snippets.

@danielgxm
Last active April 20, 2024 14:05
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 13 You must be signed in to fork a gist
  • Save danielgxm/4116672ea57350fd46c708fb5cdd897b to your computer and use it in GitHub Desktop.
Save danielgxm/4116672ea57350fd46c708fb5cdd897b to your computer and use it in GitHub Desktop.
Discord自动聊天机器人,撸白名单必备!
# -*- coding: utf-8 -*-
"""
@Time : 2021/10/3 19:18
@Auth : d1rrick DanielGao.eth
@File :autochat.py
@IDE :vscode
"""
import requests
import json
import random
import time
import re
def gen_context():
context_list = [
"hello bro", "let's go !", "to the moon!", "nice", "project", "have a good day",
"good", "luck", "how's going", "so do i", "yeah", "same to me", "1", "cool", "so far so good",
"hi~", "of course", "really", "cool~", "ok", "what?", "why?", "not bad", "well done", "great",
"perferct", "thanks", "ture", "yes", "no", "here", "interesting", "it's funny", "i am tired"
]
text = random.choice(context_list)
return text
def get_context():
chanel_list = ['891977019544457260']
headr = {
"Authorization": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx",
"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"
}
chanel_id = random.choice(chanel_list)
url = "https://discord.com/api/v9/channels/{}/messages?limit=100".format(
chanel_id)
res = requests.get(url=url, headers=headr)
result = json.loads(res.content)
result_list = []
for context in result:
if ('<') not in context['content']:
if ('@') not in context['content']:
if ('http') not in context['content']:
if ('?') not in context['content']:
result_list.append(context['content'])
return random.choice(result_list)
def chat():
chanel_list = ['891977019544457260']
authorization_list = [
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx']
for authorization in authorization_list:
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": get_context(),
"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 Exception:
print(Exception)
continue
# 取30秒到50之间的一个随机数,作为循环的间隔时间。
time.sleep(random.randrange(30, 50))
if __name__ == '__main__':
while True:
try:
print('start')
chat()
# 取180秒到240之间的一个随机数,作为机器人发送消息的间隔时间。
sleeptime = random.randrange(180, 240)
time.sleep(sleeptime)
except:
pass
continue
@danielgxm
Copy link
Author

请完整复制所有代码,然后在本地保存为.py文件。注意所有标点符号必须是半角英文格式。

@danielgxm
Copy link
Author

代码经过测试,运行正确。

@Greedy1997
Copy link

大佬 有没有使用教程

@GreenJoson
Copy link

chanel_list = ['891977019544457260'], headr = {
"Authorization": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx",需要修改的吧?

@Greedy1997
Copy link

chanel_list = ['891977019544457260'], headr = { "Authorization": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx",需要修改的吧?

是的 改成自己的auth就好了

@suixufeng
Copy link

非常感谢!

@ben316817495
Copy link

"nonce": "82329451214{}33232234".format(random.randrange(0, 1000)),
弱弱的问下,这段代码的意思是?

@ArosyYang
Copy link

headr = { "Authorization": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx",
这个怎么改

@williamlimanchun
Copy link

b'{"message": "Missing Access", "code": 50001}'
一直出现这个报错,需要怎么改呢

@Serlight
Copy link

Serlight commented Apr 3, 2023

add proxy

@luluQQQ
Copy link

luluQQQ commented May 21, 2023

請問出現以下是甚麼原因,謝謝
Traceback (most recent call last):
File "C:\discord_bot.py", line 8, in
import requests
ModuleNotFoundError: No module named 'requests'

@kkk2791
Copy link

kkk2791 commented Jul 25, 2023

可以添加多个ID吗 几个DC一起刷

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