# Sending messages as a bot

**URL:** <https://discuss.dev.twitch.com/t/sending-messages-as-a-bot/59637>\
**Category:** API\
**Created:** [July 10, 2024, 3:48pm UTC](https://discuss.dev.twitch.com/t/sending-messages-as-a-bot/59637 "2024-07-10T15:48:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ruttie](https://avatars.discourse-cdn.com/v4/letter/r/f0a364/32.png) [@ruttie](https://discuss.dev.twitch.com/u/ruttie)\
**Post date:** [July 10, 2024, 3:48pm UTC](https://discuss.dev.twitch.com/t/sending-messages-as-a-bot/59637/1 "2024-07-10T15:48:38Z")

</div>

I’m trying to send a message as my bot, but I’m running into some trouble.  
I’m making the following request:

```auto
post("https://api.twitch.tv/helix/chat/messages")
        .header("Authorization", format!("Bearer {}", token))
        .header("Client-ID", client_id)
        .header("Content-Type", "application/json")
        .json(&json!({
            "broadcaster_id": user_id,
            "sender_id": bot_id,
            "message": content
        }));

```

Where `token` is the token I got from `curl -X POST -d client_id=REDACTED -d client_secret=REDACTED -d grant_type=client_credentials "https://id.twitch.tv/oauth2/token"`, `client_id` is the client id of my bot, `user_id` is the id of the user whose chat I want to send a message to, and `bot_id` is the id of my bot user.

However, when making this request, I get a 401 stating ‘The sender must have authorized the app with the user:write:chat and user:bot scopes.’  
What am I doing wrong?

NOTE: When sending a request with `bot_id` the same as `user_id` and having `token` as the user token, it does work, but then I send a message as the user instead of as my bot, which is not what I want.

---

<div class="post-metadata">

**Author:** ![Dist](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/dist/32/7192_2.png) [@Dist](https://discuss.dev.twitch.com/u/Dist)\
**Post date:** [July 10, 2024, 6:22pm UTC](https://discuss.dev.twitch.com/t/sending-messages-as-a-bot/59637/2 "2024-07-10T18:22:07Z")

</div>

> [@ruttie](#):
>
> However, when making this request, I get a 401 stating ‘The sender must have authorized the app with the user:write:chat and user:bot scopes.’  
> What am I doing wrong?

You need the account that you wish to send messages as connect to your app, with the `user:bot` scope. Additionally the channel you wish to send messages to either needs to connect to your app with the `channel:bot` scope, or your bot needs to be a moderator in that channel.

This is mentioned in the Authorization section of the [Send Chat Message](https://dev.twitch.tv/docs/api/reference/#send-chat-message) docs.

---

<div class="post-metadata">

**Author:** ![ruttie](https://avatars.discourse-cdn.com/v4/letter/r/f0a364/32.png) [@ruttie](https://discuss.dev.twitch.com/u/ruttie)\
**Post date:** [July 10, 2024, 7:24pm UTC](https://discuss.dev.twitch.com/t/sending-messages-as-a-bot/59637/3 "2024-07-10T19:24:12Z")

</div>

I finally figured out what was wrong.  
I come from discord bot development, where bots are their own users, but this is not the case here.  
I did not realize I have to create a new twitch account for my bot in order to send and receive messages using it.  
Thank you for the suggestion though!

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [July 11, 2024, 9:37am UTC](https://discuss.dev.twitch.com/t/sending-messages-as-a-bot/59637/4 "2024-07-11T09:37:11Z")

</div>

Just curious:

> [@ruttie](#):
>
> I come from discord bot development, where bots are their own users, but this is not the case here.

If you didn’t

> [@ruttie](#):
>
> I did not realize I have to create a new twitch account for my bot in order to send and receive messages using it.

There where/how did you

> [@ruttie](#):
>
> and `bot_id` is the id of my bot user.

Get the user ID of the bot for this request?  
Without the user you wanted to send as pre-exsiting?

---

<div class="post-metadata">

**Author:** ![system](https://d2opxh93rbxzdn.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://discuss.dev.twitch.com/u/system)\
**Post date:** [August 10, 2024, 9:37am UTC](https://discuss.dev.twitch.com/t/sending-messages-as-a-bot/59637/5 "2024-08-10T09:37:45Z")

</div>

Closed on August 10, 2024, 9:37am UTC

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