Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
235 views
in Technique[技术] by (71.8m points)

python 3.x - How can I create a discord bot that will send out notifications about streams?

I need my discord bot written in PYTHON to be able to send a text chat notification about the start of the stream. I tried using webhooks in discord using the IFTTT site, but the alerts come with a huge delay. Can someone throw off some of the code for notification of streams? Thank you in advance

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use Twitch's Eventsub to recieve a notification when a Stream goes live then modify the payload to match Discord's Webhook format and forward the payload on. Which is essentially what IFTTT does anyway.

Currently EventSub only offers a Webhook Transport. So you need a "Server" that can recieve a HTTP Post from Twitch.

Twitch EventSub is covered here https://dev.twitch.tv/docs/eventsub

Discord Webhooks is covered here https://discord.com/developers/docs/resources/webhook

If you want your Discord Bot to do it itself, then you generally would not use EventSub as you don't want your Bot process to be directly web accesable, so you'd have to poll the Streams Endpoint of the Helix API periodically and test for the Stream changing from offline to online and do whatever is needed. (Or setup a side process to recieve and internal relay the data)

You would use a Twitch App Access/Client Credentials Token, since this is a server to server request.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...