首页 > 解决方案 > 使用 webhook 在不和谐服务器上创建频道

问题描述

我正在使用 discord webhook api 将消息发送到我的 discord 服务器频道。在一个新的用例中,我想创建一个带有 webhook 的新频道。不幸的是,我找不到任何 API 可以做到这一点。我在这里阅读了整个文档:https ://discordapp.com/developers/docs/resources/webhook#create-webhook

这甚至可能吗?我看到了允许它的不和谐机器人的方法 - 因此我有点认为它也应该可以通过 webhook 实现。

标签: apidiscordwebhooks

解决方案


我认为 Discord webhook 仅用于发送消息,仅此而已,如果您不想手动创建频道,您可能必须使用机器人来创建频道。

我认为仅在 rewrite 分支上支持通过 discord.py API 创建 webhook

安装 discord.py-rewrite pip install git+https://github.com/Rapptz/discord.py@rewrite

import discord
from discord.ext.commands import Bot
bot=Bot(command_prefix='.')

@bot.event
async def on_ready():
    print(bot.user.name)


@bot.command()
async def chan(msg):
    chan=await msg.guild.create_text_channel(name='New text')
    web=await chan.create_webhook(name='New web')
    print(web.url)

bot.run("YOUr bot token here")

你可以在这里找到文档,你可以在这里创建你的机器人


推荐阅读