# Token is valid but bot is failing to connect

**URL:** <https://discuss.dev.twitch.com/t/token-is-valid-but-bot-is-failing-to-connect/40678>\
**Category:** Chat and IRC\
**Created:** [September 17, 2022, 11:01pm UTC](https://discuss.dev.twitch.com/t/token-is-valid-but-bot-is-failing-to-connect/40678 "2022-09-17T23:01:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![krawf](https://avatars.discourse-cdn.com/v4/letter/k/77aa72/32.png) [@krawf](https://discuss.dev.twitch.com/u/krawf)\
**Post date:** [September 17, 2022, 11:01pm UTC](https://discuss.dev.twitch.com/t/token-is-valid-but-bot-is-failing-to-connect/40678/1 "2022-09-17T23:01:23Z")

</div>

Hello,

I am trying to connect a bot to its own channel, to read and edit messages. The authentication token seems valid:  
 ![Screenshot_746](https://d2opxh93rbxzdn.cloudfront.net/original/3X/8/4/849e95e16629ccc08def8de4db285accd5ee6cda.png)

But when connecting, it says:  
[18:57] info: Connecting to [irc-ws.chat.twitch.tv](http://irc-ws.chat.twitch.tv) on port 443…  
[18:57] info: Sending authentication to server…  
[18:57] error: Login authentication failed

Here is the code I’m using:

```auto
const tmi = require('tmi.js');

// Define configuration options
const opts = {
    options: { debug: true},
    identity: {
        username: 'krawfbot',
        password: 'oath:mytoken'
  },
  channels: ['krawfbot']
};

// Create a client with our options
const client = new tmi.client(opts);

// Connect to Twitch:
client.connect();

```

---

<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:** [September 17, 2022, 11:08pm UTC](https://discuss.dev.twitch.com/t/token-is-valid-but-bot-is-failing-to-connect/40678/2 "2022-09-17T23:08:08Z")

</div>

You have a typo in `oath:`

it should be `oauth:`

```javascript
const opts = {
    options: { debug: true},
    identity: {
        username: 'krawfbot',
        password: 'oauth:mytoken'
  },
  channels: ['krawfbot']
};

```

---

<div class="post-metadata">

**Author:** ![krawf](https://avatars.discourse-cdn.com/v4/letter/k/77aa72/32.png) [@krawf](https://discuss.dev.twitch.com/u/krawf)\
**Post date:** [September 17, 2022, 11:09pm UTC](https://discuss.dev.twitch.com/t/token-is-valid-but-bot-is-failing-to-connect/40678/3 "2022-09-17T23:09:53Z")

</div>

Of course… thank you!

---

<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:** [October 17, 2022, 11:10pm UTC](https://discuss.dev.twitch.com/t/token-is-valid-but-bot-is-failing-to-connect/40678/4 "2022-10-17T23:10:29Z")

</div>

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