问题
I was wondering how I would add a command for 'UpTime' in my commands that will show how long the twitch channel has been live for.
This is my whole code: https://pastebin.com/ty8J3vYS
Im not sure if i add it into my commands with things added to it with another case such as
case "uptime":
irc.sendChatMessage("");
break;
Any help/guidance would be great.
Thanks in advanced.
回答1:
You can use Twitch's own API for this. Using this URL:
https://api.twitch.tv/kraken/streams/CHANNEL_ID
CHANNEL_ID is numeric, so you'll have to find out what yours is.
Will return json, and within it contains the key created_at
, which tells you when a stream went live, and from there you can calculate how long the stream has been live for. (curr_date
- created_at
)
Although, you will need a Client-ID
when sending the API request. You can read more about that here:
https://blog.twitch.tv/client-id-required-for-kraken-api-calls-afbb8e95f843
Here is the documentation on Twitch's API: https://dev.twitch.tv/docs/
来源:https://stackoverflow.com/questions/44134600/uptime-twitch-command-twitchbot-c