UrlEncode usernames

Asked Jul 4, 2022·3 replies·Last activity 4 years ago·Open in Discord ↗
Archived from the original community forum
Things may have changed since it was written. Still stuck? Ask the community on Discord.

Hi,

Is there any chance you could provide a way to urlencode anything sent in an UrlFetch command because I'm having serious problems dealing with usernames with unicode characters in, in youtube chat requests. The chat messages arrive and get processed fine because you urlencode those but not so with the username attached to it. So those with foreign or unicode characters are tripping up all manner of decoding at my end.

Thanks for any help,

Pat

3 replies

Hi Emily,

Thanks for that. I do already use $querystring but that is only the message content. I am also sending the username ($user variable) which is not url encoded and as such is causing this issue.

Pat

Ah, right, sorry, I misread you.
Okay, so you'll need two commands for this, second one being the alias for the first one.

First we'll use JavaScript to encode the username:

!addcom !commandName -a=_commandName $(eval `${encodeURIComponent('$(user)')} $(querystring)`)

Then you'll call your API with the output of that command:

!addcom _commandName $(urlfetch URL?q=$(querystring))

Of course you'll need to adapt this a bit to suit your needs, but that's the main way to go about it.