问题描述
问题:我曾尝试在互联网上搜索解决方案,但似乎都没有。这主要是因为当你这样做时:(Invoke-Webrequest -Uri www.discord.com/login).Forms
,它变成空的。没有要填写的表格,所以我无法登录。
我尝试过的:
1.
$cred = Get-Credential
$login = Invoke-WebRequest discord.com/login -SessionVariable ds
$login.Forms[0].Fields.email = $Cred.Username
$login.Forms[0].Fields.pass = $cred.GetNetworkCredential().Password
$fLogin = @{
email = "email@email.net"
password = "password"
}
$login = Invoke-WebRequest -Uri 'https://discord.com/login' -SessionVariable "sv" -Form $fLogin -Method Post
解决方法
因为您正在登录,所以我假设您正在尝试制作机器人?
API 与浏览器
您需要使用 Web API 而不是自动化 UI 交互。第一个将更可靠,对变化更健壮,并使用更少的资源。
机器人的类型:
- A
WebHook
或 - 真正的机器人
如果您使用 WebHook
,则不需要机器人帐户,并且 Authentication is easier to get started with because it's not OAuth2
设置
在设置中转到:Server Settings -> Integrations -> View Webhooks
,然后创建您的网络钩子。
使用Invoke-RestMethod
发布消息
对 Web Api 使用 Invoke-RestMethod
。它简化了事情。
$webhookUri = 'https://discord.com/api/YourWebhookUrlHere'
$Body = @{
'username' = 'Nomad'
'content' = 'https://memory-alpha.fandom.com/wiki/Nomad'
}
Invoke-RestMethod -Uri $webhookUri -Method 'post' -Body $Body