使用discord API 创建discord 频道

问题描述 投票:0回答:2

我正在尝试在Python中使用discord api来处理请求,现在我正在尝试创建一个通道

这是我的代码

import requests
API_URL = "https://discord.com/api/v9"
res = requests.post(f"{API_URL}/guilds/{guild_id}/channels", data={"name": "my channel name", "permission_overwrites": [], "type": 0}, headers={"authorization": f"Bot {the_bot_token}", "Content-Type": "application/json"})
print(res.text)

但它给了我这样的回应:

{"message": "400: Bad Request", "code": 0}

有人可以帮助我吗?

python python-3.x api python-requests discord
2个回答
1
投票

好吧,你的代码是错误的,你搞砸了请求数据

你应该将数据替换为json

这是工作代码

import requests
API_URL = "https://discord.com/api/v9"
res = requests.post(f"{API_URL}/guilds/{guild_id}/channels", json={"name": "my channel name", "permission_overwrites": [], "type": 0}, headers={"authorization": f"Bot {the_bot_token}", "Content-Type": "application/json"})
print(res.text)

0
投票

您的

permission_overwrites
字段可以删除,因为在 创建频道文档中,

它说:

此端点的所有参数都是可选的且可为空,除了

name

© www.soinside.com 2019 - 2024. All rights reserved.