Page 1 of 1

Send message to discord by gui button

Posted: 21 Jan 2022, 14:25
by Linnitry
I'm trying to make a gui panel to simplify the usage of bot-commands in my server. However, no message is sent. Very noob on AHK so I'm not really sure what to look for. The script I got is copy-pasted together from examples. The result I'm looking for is that the message blaaaaaah is sent to discord when I press the button.

Grateful for any pointers :)

Code: Select all

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

gui, add, button, x5 y5 h20 w70 gsub1, Subroutine 1 
gui, add, button, x5 y30 h20 w70 gexit, Exit Script
gui, show, w80

WinGetActiveTitle, Window_name
Win_Discord := "DISCORD"
Found_Discord := InStr( Window_name, Win_Discord, false )   ;AHK builtin function
return

sub1:
{
   If  !( Found_Discord >= 1 )
   {
      MsgBox, 1,!!WARNING!! ,The Client Window "%Win_Discord%" NOT Found.  Found "%Window_name%"%lf_char%%lf_char%Press ENTER Key to Ignore Warning and Continue., 5  ; -seconds before timeout.
      IfMsgBox, Cancel
      exit  ; User pressed the "Cancel" button.
      IfMsgBox, Timeout  
      {
         SplashTextOn,,, Script EXITING Now
         Sleep 2000
         SplashTextOff
         exit ; i.e. Assume "Cancel" if it timed out.
      }
   }
   WinActivate, Window_name
   Send blaaaaaah
}
return

guiclose:
exit:
 {
   exitapp
 }
return

Re: Send message to discord by gui button

Posted: 21 Jan 2022, 17:05
by mikeyww
AHK commands use literal strings, so flank your variable names in %.

Code: Select all

WinActivate, %Window_name%

Re: Send message to discord by gui button

Posted: 14 Feb 2022, 02:11
by itsholy
You can send a msg with a simple msg http request.

Code: Select all

TOKEN:="YOUR ACC TOKEN"
URL := "https://discord.com/api/v8/channels/ID_OF_CHANNEL/messages"
payload := {"content":"TEXT HERE", tts: false}

WebRequest := ComObjCreate("WinHTTP.WinHTTPRequest.5.1")
WebRequest.Open("POST",URL, False)
WebRequest.SetRequestHeader("Authorization", TOKEN)
WebRequest.SetRequestHeader("Content-Type", "application/json")
WebRequest.Send(JSON.Dump(payload))
Requires JSON.akh

Re: Send message to discord by gui button

Posted: 18 Sep 2022, 22:57
by pcshooter2425
How do you get your account token?

Re: Send message to discord by gui button

Posted: 18 Sep 2022, 23:03
by BoBo
pcshooter2425 wrote:
18 Sep 2022, 22:57
How do you get your account token?
Normally you'll get it from the provider of the API. The standard is to register an account. Check its FAQ.