我有一个用蟒蛇写的机器人。帮助我处理HTTP请求。有一个任务:在命令中重命名频道。但是不和谐对频道的重命名有一个限制( 10分钟内2次)。我需要在几秒钟内从API中获得一个定时器,并将它插入到一个条件中(如果计时器大于0,则发送带有计时器的消息)。我不知道这个计时器是从哪里来的..。我尝试了不同的urls:https://discord.com/api/v9/applications/*app id*、https://discord.com/api/v9/channels/{ctx.channel.id}、https://discord.com/api/v9/users/*bot id*。在最后一个url中,我找到了速率限制标头,但是还有一些定时器没有准确显示频道重命名的限制。
这是我的密码:
@bot.command()
async def rename(ctx, *, name):
await ctx.message.delete()
headers={
'authorization': 'Bot *Secret token :)*'
}
response = requests.head(f'*I do not know which link to insert here :(*', headers=headers)
limit = response.headers('X-RateLimit-Reset-After') #I need there to be a timer that shows after how many seconds the bot will be able to rename the channel
if limit == 0:
await ctx.channel.edit(name=f'{name}')
if limit > 0:
await ctx.channel.send(f'Can`t rename. Pls, wait {limit} seconds')
发布于 2022-04-14 23:50:02
当您试图对端点执行请求时,将显示速率限制标头,但失败。因此,要在几秒钟内获得棘轮定时器,您可以这样做:
import requests, json
try:
r = request.post("channel rename url", headers={"authorization": "Bot token"}, json={"json"})
except:
data = r.json()
limit = data["retry_after"]
print(limit)
如果有些错误,请纠正我。我有一段时间没用过请求了。
https://stackoverflow.com/questions/71700069
复制相似问题