How can i send messages with announce format with a Twitch Bot?

Hi, i know this method to send announces:
await TheTwitchAPI.Helix.Chat.SendChatAnnouncementAsync(broadcasterId:, moderatorId: , message: “”, color: , accessToken: );

But i have a problem. Im connecting 2 accounts, Owner and Bot to an Owner’s Channel, and the accessToken have Owner’s channel ID instead of Bot ID so when i use Bot ID on “moderatorId:” parameter it throw an exception.

The other way i know is using “/announce” but if i use this at start of a message the message is not sended. (If i write “/me” at start of message the message is sended and coloured perfectly)

What do you recommend me to do?

This method is deprecated.

Make sure you are using the correct token.

if you want to send an announcement as the bot then you need to be using the bots token.

The clue is in the text you already wrote. You just are not token switching when you need to.

Ill try some things, in some hours ill send you a reply, i think i have the answer. Sorry for your time.

How can i get bots token without having the bot account connected in browser?

Context:
Im using the method of the following video to get the access token “Create Your Own TwitchBot in C# using OAuth (with TwitchLib) - BEGINNER FRIENDLY - YouTube”.

Problem:
I have an Channel account, Bot account and AppUser Account (this one is not neccesary to use it).

The User of App have acces to Channel account and AppUser account.

I want to send an announce with Bot Account in Channel account. The problem is, the way im using to get access token implies have connected Bot Account in the predetermined browser.

Ask: How can i send the announce with Bot account without having the account conected in browser?

You don’t

The user has to use a browser to grant your clientID permissions

You don’t. You have to use a browser to grant permissions

I want to do this:

How can i do then?

Generate an oAuth token as documented.
Then use that oAuth token as documented to make an announcement.

You already stated how to do it here.

You just need to feed in the bots token.

Which you state you already did here as you have a bot token.

I’m not sure what your issue is as everything you need you already described.

You state your are connecting accounts which implies to me you have done oAuth flows to obtain a casters token and a bot token to use. So you should have everything you need.

Im using this to connect Owners account:
WebServer.RequestReceived += async (s, e) =>
{
using (var writer = new StreamWriter(e.Response.OutputStream))
{
if (e.Request.QueryString.AllKeys.Any(“code”.Contains))
{
var code = e.Request.QueryString[“code”];
var ownerOfChannelAccessAndRefresh = await getAccessAndRefreshTokens(code);
CachedOwnerOfChannelAccessToken = ownerOfChannelAccessAndRefresh.Item1;
SetNameAndIdByOauthedUser(CachedOwnerOfChannelAccessToken).Wait();
InitializeOwnerOfChannelConnection(TwitchChannelName, CachedOwnerOfChannelAccessToken);
InitializeTwitchAPI(CachedOwnerOfChannelAccessToken);
}
}
};

Im using this to connect bot:

private Task ConnectBot()
{
var credentials = new ConnectionCredentials(nombreBot, oauthClave);
BotClient.Initialize(credentials, TwitchChannelName);
BotClient.OnConnected += BotClient_OnConnected;
BotClient.OnChatCommandReceived += Bot_OnChatCommandReceived;
BotClient.Connect();
return Task.FromResult(true);
}

And this to send the announce:
await TheTwitchAPI.Helix.Chat.SendChatAnnouncementAsync(broadcasterId: TwitchChannelId, moderatorId: BotChannelId, message: “El Anuncio esta funcionando”, color: announceColor, accessToken: <oauthClave/CachedOwnerOfChannelAccessToken both throw exception>);

It throw this:
TwitchLib.Api.Core.Exceptions.BadScopeException: ‘Your request was blocked due to bad credentials (Do you have the right scope for your access token?).’

Do you have the correct scope(s) on the bot’s token?

moderator:manage:announcements

The way i connect the bot is using this: < Twitch Chat Password Generator >
and then <var credentials = new ConnectionCredentials(nombreBot, oauthClave);
BotClient.Initialize(credentials, TwitchChannelName);>

With that i can use <BotClient.OnChatCommandReceived> and then <BotClient.SendMessage()>

But cant use <await TheTwitchAPI.Helix.Chat.SendChatAnnouncementAsync(broadcasterId: TwitchChannelId, moderatorId: BotChannelId, message: “”, color: announceColor, accessToken: CachedOwnerOfChannelAccessToken);> because the token i generate is using Owner Channel Account instead of Bot Account.

I dont know how to generate accessToken with that scope to SendChatAnnouncement WITHOUT login in predetermined browser my Bot Account.

Just an other question because as you can see im noob, Why dont you implement <Client.SendChatAnnouncement()> or maybe is there a way to do it and i dont know it.

You really shouldb’t be using someone elses token generator.

To get a token for account foo login to foo in a browser then run an oauth flow to generate a token.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.