No badge is issued chat bot badge

Hi, my bot contains these lines

await twitch.send_chat_message(br_id, mod_id, 'mytext')

and

target_scope = [AuthScope.CHAT_READ, AuthScope.CHANNEL_BOT, AuthScope.MODERATOR_MANAGE_ANNOUNCEMENTS, AuthScope.USER_BOT, AuthScope.USER_WRITE_CHAT, AuthScope.CHAT_EDIT, AuthScope.CHANNEL_MANAGE_BROADCAST,
                AuthScope.MODERATOR_MANAGE_BANNED_USERS, AuthScope.CLIPS_EDIT, AuthScope.CHANNEL_BOT, AuthScope.MODERATOR_READ_CHATTERS]

but the bot is not given a badge
What’s wrong and what needs to be added?

Are you using an App token or a User Token?

Also, have you gotten the correct permissions from the correct users? eg, you need user:bot from the channel you wish to use as a bot, and either channel:bot from the channel you wish to send messages in or be a moderator in that channel?

I have permission because I am a moderator.
The token was created on the website twitchtokengenerator.com

First off, it’s not recommended to use 3rd party token generators.

Secondly, that’ll get you a User Token, which isn’t eligible for the Bot Badge, you need to use an App Token, which you should be generating yourself within your app.

Can I get the tokens I need with this request?

import requests

def get_tokens(client_id, client_secret, code, redirect_uri):
    url = "https://id.twitch.tv/oauth2/token"
    params = {
        "client_id": client_id,
        "client_secret": client_secret,
        "code": code,
        "grant_type": "authorization_code",
        "redirect_uri": redirect_uri
    }
    response = requests.post(url, params=params)
    return response.json()

tokens_info = get_tokens("#", "#", "#", "http://localhost:17563")
print(tokens_info)

No, that’s a User Token. You need to use an App token from the Client Credentials flow https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/#client-credentials-grant-flow

grant_type Yes String Must be set to client_credentials Where can I get it?

For the grant type you literally send the string: client_credentials

One more question
This query only returns access_token, but i need refresh too

    token = "#"
    refresh_token = "#"

    await twitch.set_user_authentication(token, target_scope, refresh_token)

oh no

I found a method for the app

my mistake, sry

As a developer, how can my bot appear as a Chat Bot in the viewership list?

Your bot will automatically be displayed in the “Chat Bots” section of the viewership list when listening to chat via the Channel Chat Message EventSub event with an app access token and has the channel:bot scope for the channel.

This is from the badge documentation
but I don’t quite understand how to do it “listening to chat via the Channel Chat Message EventSub even“

twitch = Twitch('#', '#')

br_id = "#"

channel_name = "#"

mod_id = "#"


async def on_ready(ready_event: EventData):
    await ready_event.chat.join_room(channel_name)
    logger.success(F"BOT {channel_name} READY")

async def test(chatmes: ChatCommand):
    await twitch.send_chat_message(br_id, mod_id, 'text')


async def run_bot():
    init_db()
    target_scope = [AuthScope.CHAT_READ, AuthScope.CHANNEL_BOT, AuthScope.MODERATOR_MANAGE_ANNOUNCEMENTS, AuthScope.USER_BOT, AuthScope.USER_WRITE_CHAT, AuthScope.CHAT_EDIT, AuthScope.CHANNEL_MANAGE_BROADCAST,
                    AuthScope.MODERATOR_MANAGE_BANNED_USERS, AuthScope.CLIPS_EDIT, AuthScope.CHANNEL_BOT, AuthScope.MODERATOR_READ_CHATTERS]

    app_token = "#"
    user_token = "#"
    refresh_token = "#"

    await twitch.set_user_authentication(user_token, target_scope, refresh_token)

    await twitch.set_app_authentication(app_token, target_scope)


    chat = await Chat(twitch)

    
    chat.register_command("test", test)

    chat.register_event(ChatEvent.READY, on_ready)

    chat.start()

    try:
        await asyncio.Event().wait()
    except (KeyboardInterrupt, asyncio.CancelledError):
        logger.info("off")
    finally:
        chat.stop()
        await twitch.close()
        client_socket.close()
        logger.info("off")


asyncio.run(run_bot())

It appears you’re trying to connect to chat over IRC, which is completely separate from EventSub. I’d recommend reading the EventSub documentation to see how to subscribe to a topic https://dev.twitch.tv/docs/eventsub/

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