Send message to discord by gui button

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Linnitry
Posts: 1
Joined: 21 Jan 2022, 14:17

Send message to discord by gui button

Post by Linnitry » 21 Jan 2022, 14:25

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

User avatar
mikeyww
Posts: 26599
Joined: 09 Sep 2014, 18:38

Re: Send message to discord by gui button

Post by mikeyww » 21 Jan 2022, 17:05

AHK commands use literal strings, so flank your variable names in %.

Code: Select all

WinActivate, %Window_name%

itsholy
Posts: 2
Joined: 14 Feb 2022, 02:06

Re: Send message to discord by gui button

Post by itsholy » 14 Feb 2022, 02:11

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

pcshooter2425
Posts: 1
Joined: 18 Sep 2022, 22:54

Re: Send message to discord by gui button

Post by pcshooter2425 » 18 Sep 2022, 22:57

How do you get your account token?

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Send message to discord by gui button

Post by BoBo » 18 Sep 2022, 23:03

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.

Post Reply

Return to “Ask for Help (v1)”