Unable to subscribe my bot to chat via EventSub with Godot

Hello everyone,

I’ve been working with Godot to connect to chat, I would like to use the EventSub but I’m hitting a wall in the last step (if that’s where the issue is). I would like to list the things I’ve done:

I have a bot account where I registered a new Private app to get the client_id and the client_secret.

With that I proceed to Godot with the following steps.

  1. First I ask for the Oauth token for the bot account with the scopes: user:read:chat and user:bot

This is the Body I’m creating

	var body = "client_id=%s&client_secret=%s&grant_type=%s&scope=%s" % \
	[
		bot_client_id,
		bot_client_secret,
		"client_credentials",
		"user:read:chat user:bot"
	]

Thanks to this I get the Oauth Token. At this point, I have the Client_Id, the Client_secret and an Oauth Token for my bot account with the scopes to be able to read chat.

  1. After this, I need the broadcast_id of my channel. So I use the oauth token and client_id I have to get it.

Everything looks OK and I am able to get the Id.

Now I have also my channel’s broadcaster_user_id.

  1. Now I establish the connection with the EventSub. For this I don’t use any parameter I have up to now, I just connect and I receive the session_welcome message. I keep the session_id from this response.

Now I also got the session_id.

  1. Finally comes the subscription step. I use this values to make a POST to the subscription endpoint: “https://api.twitch.tv/helix/eventsub/subscriptions

At the headers I set the authorization with my bot’s Oauth Token, the client with the bot’s Client_id.
At the body I set the scope to channel.chat.message, the broadcaster_user_id and the session_id

	var url = "https://api.twitch.tv/helix/eventsub/subscriptions"
	var headers = [
		"Authorization: Bearer " + bot_oauth_token,
		"Client-Id: " + bot_client_id,
		"Content-Type: application/json"
	]
		
	var body = JSON.stringify({
	"type": "channel.chat.message",
	"version": "1",
	"condition": {
		"broadcaster_user_id": broadcaster_id
	},
	"transport": {
		"method": "websocket",
		"session_id": event_bus_session_id
	}
	})

And after all this I receive a 400 error.

I also tried adding the “user_id” at the condition part with the bot’s broadcast_id, that way I get a 403.
{"error":"Forbidden","status":403,"message":"subscription missing proper authorization"}.

I just don’t know what I did wrong. Did I make a wrong turn in one of the steps?
I tried to validate the Oauth token and it says that it’s ok and the scopes appear correctly.
If it helps, the bot account is a moderator in my channel.

That gives you an App Token, it’s not in any way related to your bot account.

As the documentation states for channel.chat.message

Requires user:read:chat scope from the chatting user. If app access token used, then additionally requires user:bot scope from chatting user, and either channel:bot scope from broadcaster or moderator status.

So you have the App access token, but you need the user you wish to connect to chat as (your bot) to go through one of the User OAuth flows and grant the user:bot scope, and your need the broadcaster to mod the bot, or go through the OAuth flow and grant the channel:bot scope.

I think I understand. I have to change my App Access Token process to be a User Access Token.

This process will make that my game won’t be able to subscribe to the events without user interaction, isn’t it?

There is then no option to make it automatic to get this kind of connection?

Thank you very much!

for a game you would want to be subscribing to data relating to the broadcaster, so broadcasters expect to authorize themself.

Especially if you want to utilize things such as channel points. (not just chat) so without an external service to run a bot, if you want the game to talk directly to chat/not vaa a relay/external service, then you need to get the broadcaster to auth.

This would likely be via DCF/Device Code Flow - Getting OAuth Access Tokens | Twitch Developers

1 Like