Add a property to a user


Hi folks,

New here – loving Phantombot. I play a lot of Blizzard games and would like to be able to add a user’s Battletag to their account. It feels like it would be adding a property to the user’s record in the PB DB. I would envision the command to be as such:

User: !btag zombiebrainz#1234
System: Thanks for submitting your battletag Zombiebrainz

if I want to play with someone, I could do:
User: !btag zombiebrainz
System: Zombiebrainz’s battle tag is: zombiebrainz#1234

I don’t know where to start… Sorry if I didn’t post this in the correct area.



Each data set in PhantomBot is a table. The tables are generic key/value stores (which do have one additional grouping key as well to encapsulate a set of keys/values).

Are you asking for someone to write the script, or for some help in writing one yourself?



Thanks @IllusionaryOne

I could try to write it myself but I was asking to see if there was something similar (or some framework) that I could look at and tailor for my own needs (and share back with the community).


Nothing exactly like that, which I can think of. You can take any script for the handling of commands, like, look at this post:

Very simple script that runs one command. Be sure to change the command names and the script name in $.registerChatCommand(). You can also change the ‘1’ on that to a ‘7’ for all viewers to be able to run.

Now, the guts will be different. You will be using:

$.setIniDbString('battletag', sender, args[0]); to set the tag and
$.getIniDbString('battletag', sender, 'Not provided'); to get the tag back.

The first parameter to those calls is the table name, the second is the key. On the set function, the third argument is what to set the value to. On the get function, the third argument is what to return if a key is not found in the DB.

Now, what you will probably want to do is either have two commands like !setbtag and !btag or work with parameters on !btag to have !btag set [id] and !btag [user] (if someone on Twitch is named ‘set’, oh well). Or, and I don’t know a lot about Battletags, but, if all battle tags have a hashtag (#) in them, then I suppose you could write logic to say if the argument contains a ‘#’ then set a value, else, try to retrieve one.

You can check to make sure the user provides a parameter with if (args[0] === undefined) to catch and return a usage to the user.

To submit to PhantomBots GitHub, if possible, check out the $.lang.register() functions, so that the settings are not hard-coded into a script. However, there is nothing wrong with posting to the forums using hard-coded outputs.


@IllusionaryOne thanks! this is great – I will certainly look into this. Awesome


@IllusionaryOne Worked great - thanks for your help.

Wondering if I can pick your brain for a ‘dumb’ question. I’m trying to respond a usage msg if the user does not enter an argument to the command. I’ve combined the read and write into 1 command so I want to do something like (I would put the following on 1 line - separated for legibility) :

$.say(“Usage 1: !btag <user_name> to retrieve the user’s battle tag\n
Usage 2: !btag <yourtag#123> to set your battletag”);

I’m trying to enter a new line… is that possible? Otherwise, I will just issue 2 say commands as a workaround.

thanks again for your time


Twitch doesn’t allow us to enter newlines, unfortunately (or fortunately). Do be careful with a lot of output, we have a limit of 20 lines in 30 seconds, and (you don’t need to share but) in busy chats that can make the bot put items into a queue to be spit out when it is able to.

What I like to do for usage, for what you are saying:

!btag [twitch user | yourtag#123] : Provide a user to look up from chat or your own tag to share with others.


makes sense - will do that - thanks again wise one :smile: