我需要更改什么才能使用 python 向不和谐频道发送消息和图像?

问题描述 投票:0回答:1
import requests
import time

Url = "discord_channel"
auth = {
    'authorization': 'Token'
}

msg = {
    'content':''
}

for i in range():
     time.sleep()
     requests.post(Url, headers = auth, data = msg)`

这就是我使用的,但我也想添加图像,但我尝试了一切但没有任何效果,有人可以帮助我,以便我可以发送图像和消息吗? 我用它来发送消息和交易,我需要发送图像,以便他们可以看到我交易的内容,任何帮助都有效

我尝试使用discord.py,但没有成功。

python discord discord.py
1个回答
0
投票
import requests

url = "<discord webhook url>"

# The path to your image file
file_path = 'image.png'

# Open the file in binary mode
with open(file_path, 'rb') as f:
    # Define the multipart/form-data payload
    payload = {
        'file': (file_path, f, 'application/octet-stream')
    }
    # Send the POST request
    response = requests.post(url, files=payload)

print(response.text)
© www.soinside.com 2019 - 2024. All rights reserved.