首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >删除Webhooks Discord.py

删除Webhooks Discord.py
EN

Stack Overflow用户
提问于 2022-04-16 19:37:26
回答 2查看 779关注 0票数 0

在discord.py中,我知道您可以使用:message.channel.create_webhook(name = 'something')创建webhooks

但我不知道有没有办法把它们删除。这个是可能的吗?谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-04-17 02:51:10

AxelSparrow的方法绝对更干净,但是有一种通过webhook.delete()删除它们的内置方法,尽管这可能有点“磨损”,因为如果您只有web钩子的名称,就必须使用for循环。在下面的代码片段中,我将提供两个可以使用的方法。

代码语言:javascript
复制
# 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文档。

票数 1
EN

Stack Overflow用户

发布于 2022-04-16 20:59:54

没有内置的方法来做这件事,您需要手动发送http请求。

(编辑-似乎我错了:正如Bagle的答案所示,确实有一个内置的方法来删除webhooks。然而,这种方法仍然有效,而且对眼睛来说更容易一些。)

类似于:

代码语言:javascript
复制
await ctx.bot.http.request(Route('DELETE', '/webhooks/{webhook_id}', webhook_id=webhook_id))

您可能需要对此进行调整,以便在您的实现中工作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71896952

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档