TwitchLib icon indicating copy to clipboard operation
TwitchLib copied to clipboard

Getting the client's username

Open TheDiB opened this issue 3 years ago • 1 comments

Hi :) I am building my own chatbot for my Twitch.TV channel "La_DiBerie" and from now it has been working fine, thanks to the teams great work. However I am facing an issue that I haven't been able to resolve by myself : I want to exclude the chatbot from several functions such as user rankings for instance.

The project is written in C# and comes with an SQL Server dedicated database for data storage. I am using different Twitch accounts for the chatbot ("DiBerieBot") and the broadcaster ("La_DiBerie"). I could not manage to get the formers username because my TwitchClient instance only contains informations about the broadcasters account.

So, how can I get the User Access Token owner username ?

Here is a caption of the ChatBot.cs file wich contains the code I use for my chatbot to get connected to the chat :

public ChatBot(string accessToken, string twitchLogin) { channelName = twitchLogin; ConnectionCredentials credentials = new ConnectionCredentials(twitchLogin, accessToken); var clientOptions = new ClientOptions { MessagesAllowedInPeriod = 750, ThrottlingPeriod = TimeSpan.FromSeconds(30) }; WebSocketClient customClient = new WebSocketClient(clientOptions); client = new TwitchClient(customClient); client.Initialize(credentials, twitchLogin); ... client.Connect(); }

The accessToken parameter is the User Access Token obtained for the "DiBerieBot" Twitch user The twitchLogin parameter is the channels name "La_DiBerie"

client.TwitchUsername contains "La_DiBerie", the broadcasters name.

Thanks for you help ! Kind regards, Damien POINTON

TheDiB avatar Jul 23 '22 14:07 TheDiB

so do you have a GUI for entering this kind of user information?

you probably need to track that through the GUI/however it's entered into the app.

I have my own chat bot using this TwitchLib, https://github.com/WrithemTwine/TwineChatBot. It uses a GUI to track the account names: image These are stored and are persistent between sessions. I could filter out the bot username if I want-actually, that might be a good idea to add this feature...sometime.

WrithemTwine avatar Sep 09 '22 00:09 WrithemTwine