所以,我有一个“白名单”命令,我希望我的机器人发送一个 webhook,例如“新白名单请求”,但我不知道如何操作。
这是代码:
@client.tree.command(guild=TEST_GUILD, description="Whitelist")
async def whitelist(interaction: discord.Interaction):
# Send the modal with an instance of our `Whitelist` class
# Since modals require an interaction, they cannot be done as a response to a text command.
# They can only be done as a response to either an application command or a button press.
await interaction.response.send_modal(Whitelist())
尝试按照文档添加:
webhook = DiscordWebhook(url="your webhook url", content="Webhook Message")
response = webhook.execute()
我尝试将 webhook URL 添加到我的响应中,但没有成功。
不确定您从哪里得到的,但这肯定不是正确的文档。
来自文档,
from discord import Webhook
import aiohttp
async def foo():
async with aiohttp.ClientSession() as session:
webhook = Webhook.from_url('url-here', session=session)
await webhook.send(content='Hello World', username='Foo')
DiscordWebhook
不存在,除非您从第三方模块导入。
阅读更多关于 discord.Webhook、Webhook.send。