#Hmmm how do I fix this?

1 messages · Page 1 of 1 (latest)

upper haven
#

Getting error


13     var request = new HttpRequest(oauthUrl);```

when I try using requests. Any ideas?
#

I have
import { http } from "@minecraft/server-net";

request.method = HttpRequestMethod.POST;```
Etc
wispy haven
#

because you have to import HttpRequest, not http

#

http is nothing

#

but since you'd likely be needing to use everything in the server-net module, do
import * as http from "@minecraft/server-net"

and then
var req = new http.HttpRequest(url)

willow iris
upper haven
#

aight so apparently request.body does not have a native handle?

#

any ideas?

#

ive been trying for hours 😂

upper haven
willow iris
#

code?

upper haven
#
function sendDiscordWebhook(message) {
    var tempplayer = world.getAllPlayers()[0]
    tempplayer.runCommandAsync(`say ${message}`)

    var request = new http.HttpRequest(webhookUrl)
    request.method = http.HttpRequestMethod.POST
    var data = { "content": message, "username": "PlayerPSB", "avatar_url": avatar_url }
    request.headers = [new http.HttpHeader("Content-Type", "application/json")]
    try {
        request.body = data
    } catch (e) {
        tempplayer.runCommandAsync(`say ${e}`)
    }
    http.request(request)
}```
#

ive literally tried so many things

willow iris
#

uhhh holdon

#

btw 3 questions:

  1. why var, u should use const/let
  2. why tempplayer
  3. why runCommandAsync to do /say instead of world.sendMessage
upper haven
#

I'm a noob at this ahah

#

Last time i did scripts was gametest lmao

willow iris
#

pffff

#

i suggest learning the basics first

upper haven
#

I managed to get chat ranks and custom emojis working - thats about all we could do lol

willow iris
#

server-net is generally pretty stupid

upper haven
#

gotcha

willow iris
#

so you should get some experience with other parts of the script api first

upper haven
willow iris
#

ew python

upper haven
#

wowww

willow iris
#

lol

upper haven
#

lol

willow iris
#

i hate that snake

upper haven
#

always been envious of the JS writers tho - web based programs are goated

willow iris
#

especially the syntax

upper haven
#

nah the syntax is bliss for me lmao

willow iris
willow iris
#

i hate it

willow iris
#

i love typescript lol

#

oh btw you are on bds right

upper haven
#

lool it was ts that i used with gametest - idk i just wanted to learn js too

willow iris
#

server-net only works on there

upper haven
#

yus

willow iris
#

hm

upper haven
#

I moved from shockbyte to Bisect cos omg shockbyte is shocking

willow iris
#

you should come use my hosting lulw

#

its in my about me if you wanna check it out, don't want to advertise in here

#

lol

upper haven
#

lol

#

not me missing async

#

🤡

willow iris
#

lmao

upper haven
#

arghh

willow iris
#

i hate that there isnt sync methods for webrequests in server-net

#

async is kinda buggy with the scripting api

upper haven
#

fr

willow iris
#

things take a lot more time than they should for some reason

#

i get like 50ms ping with these webrequests just because of how mc handles async

upper haven
#

YASSS it worked

willow iris
#

lol nice

upper haven
#

Tysm for ur help! <3

#

I need a custom emoji in there now ehhe

willow iris
#

np lol

willow iris
#

if u mean on discord

upper haven
#

yuss