使用 python 创建 Discord Webhook

Man*_*j A 2 python webhooks discord discord.py

使用 python 创建 Discord Webhook 我最近正在使用 python 开发一个 Discord 机器人。我的不和谐机器人需要通过“DISCORD WEBHOOK”发送消息。问题是我找不到使用 python 自动创建不和谐 webhook 的方法!有什么办法可以做到吗!

import discord
client = discord.Client()
@client.event
async def on_message(message):
    if message.content == 'createhook':
        #code to create a webhook in that current channel
client.run("token")
Run Code Online (Sandbox Code Playgroud)

Tin*_*yen 5

https://discordpy.readthedocs.io/en/latest/api.html#discord.TextChannel.create_webhook

你需要一个discord.TextChannel对象。
在您的情况下,您可以使用 获取消息对象的通道message.channel看这里

要创建 webhook,您需要执行以下操作message.channel.create_webhook(name="mywebhook")