在discord.py中,我知道您可以使用:message.channel.create_webhook(name = 'something')创建webhooks
但我不知道有没有办法把它们删除。这个是可能的吗?谢谢
发布于 2022-04-17 02:51:10
AxelSparrow的方法绝对更干净,但是有一种通过webhook.delete()删除它们的内置方法,尽管这可能有点“磨损”,因为如果您只有web钩子的名称,就必须使用for循环。在下面的代码片段中,我将提供两个可以使用的方法。
# Method 1: Directly using the information from creating the webhook
hook = message.channel.create_webhook(name = 'something') # create a variable
# await hook.send("test")
await hook.delete() # then delete based on variable
# Method 2: Only use this if you don't have the webhook's other information
# get all the webhooks in a channel ⬇️
channel_webhooks = await message.channel.webhooks()
for webhook in channel_webhooks: # iterate through the webhooks
if webhook.name == "something":
await webhook.delete()
break如果需要进一步的信息或理解,请随时查看class discord.Webhook文档。
发布于 2022-04-16 20:59:54
没有内置的方法来做这件事,您需要手动发送http请求。。
(编辑-似乎我错了:正如Bagle的答案所示,确实有一个内置的方法来删除webhooks。然而,这种方法仍然有效,而且对眼睛来说更容易一些。)
类似于:
await ctx.bot.http.request(Route('DELETE', '/webhooks/{webhook_id}', webhook_id=webhook_id))您可能需要对此进行调整,以便在您的实现中工作。
https://stackoverflow.com/questions/71896952
复制相似问题