# Creating an IRC Bot

**URL:** <https://staging-discuss.dev.twitch.com/t/creating-an-irc-bot/41>\
**Category:** API\
**Created:** [June 24, 2013, 6:26pm UTC](https://staging-discuss.dev.twitch.com/t/creating-an-irc-bot/41 "2013-06-24T18:26:23Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![EliteCanadian](https://avatars.discourse-cdn.com/v4/letter/e/3d9bf3/32.png) [@EliteCanadian](https://staging-discuss.dev.twitch.com/u/EliteCanadian)\
**Post date:** [June 24, 2013, 6:26pm UTC](https://staging-discuss.dev.twitch.com/t/creating-an-irc-bot/41/1 "2013-06-24T18:26:24Z")

</div>

I’ve created myself an irc bot based off this: [http://www.jibble.org/pircbot.php](http://www.jibble.org/pircbot.php) - basically, everytime I try to check myself as an operator this is my code:

```
 boolean op=false;
        for (User user : getUsers(channel)) {
            if (sender.equals(user.getNick())) {
                if (user.isOp()) op=true;
            }
        }

```

When I try to run one of my commands like !restrict test - or !addcommand test 123 test. It doesn’t work, but I check if they are operator before hand. Is there anyway to check if they are operator or something wrong with my code?

---

<div class="post-metadata">

**Author:** ![george](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/george/32/120_2.png) [@george](https://staging-discuss.dev.twitch.com/u/george)\
**Post date:** [June 24, 2013, 9:53pm UTC](https://staging-discuss.dev.twitch.com/t/creating-an-irc-bot/41/2 "2013-06-24T21:53:36Z")

</div>

Are you seeing a +o mode set before the user attempts to execute the command? Example from Pircbot with verbose logging on:

> 1372110427250 :jtv MODE #channelname +o username

The Twitch chat server is “slow” when setting the op mode when a moderator joins a channel or you join into a channel with the user already there so it might take 30 seconds or more before you receive the +o.

---

<div class="post-metadata">

**Author:** ![EliteCanadian](https://avatars.discourse-cdn.com/v4/letter/e/3d9bf3/32.png) [@EliteCanadian](https://staging-discuss.dev.twitch.com/u/EliteCanadian)\
**Post date:** [June 24, 2013, 10:00pm UTC](https://staging-discuss.dev.twitch.com/t/creating-an-irc-bot/41/3 "2013-06-24T22:00:40Z")

</div>

As you can see here, i’m an operator, red is blanked out for usernames.  
[![](https://staging-discuss.dev.twitch.com/uploads/default/238/8db67f4383ea4948.png)](https://staging-discuss.dev.twitch.com/uploads/default/238/8db67f4383ea4948.png)  
[![](https://staging-discuss.dev.twitch.com/uploads/default/239/46a33367a5e41410.png)](https://staging-discuss.dev.twitch.com/uploads/default/239/46a33367a5e41410.png)

But yeah, this is basically it.

---

<div class="post-metadata">

**Author:** ![george](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/george/32/120_2.png) [@george](https://staging-discuss.dev.twitch.com/u/george)\
**Post date:** [June 24, 2013, 11:06pm UTC](https://staging-discuss.dev.twitch.com/t/creating-an-irc-bot/41/4 "2013-06-24T23:06:06Z")

</div>

Are any users being detected as ops? Maybe try iterating through the user list after the bot has been in the channel for a few minutes and display their isOp() status. That would rule out any issues with the framework supporting Twitch’s IRC implementation.

I use Pircbot as well but I’ve had to modify it considerably over the past couple of years to support legacy JTVIRC and now TMI.

---

<div class="post-metadata">

**Author:** ![EliteCanadian](https://avatars.discourse-cdn.com/v4/letter/e/3d9bf3/32.png) [@EliteCanadian](https://staging-discuss.dev.twitch.com/u/EliteCanadian)\
**Post date:** [June 24, 2013, 11:08pm UTC](https://staging-discuss.dev.twitch.com/t/creating-an-irc-bot/41/5 "2013-06-24T23:08:33Z")

</div>

Do you think if I personal message you my code, you can check it out?

---

<div class="post-metadata">

**Author:** ![EliteCanadian](https://avatars.discourse-cdn.com/v4/letter/e/3d9bf3/32.png) [@EliteCanadian](https://staging-discuss.dev.twitch.com/u/EliteCanadian)\
**Post date:** [June 25, 2013, 9:51pm UTC](https://staging-discuss.dev.twitch.com/t/creating-an-irc-bot/41/6 "2013-06-25T21:51:02Z")

</div>

Am I allowed to private message you it or not?

---

<div class="post-metadata">

**Author:** ![george](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/george/32/120_2.png) [@george](https://staging-discuss.dev.twitch.com/u/george)\
**Post date:** [June 25, 2013, 10:58pm UTC](https://staging-discuss.dev.twitch.com/t/creating-an-irc-bot/41/7 "2013-06-25T22:58:16Z")

</div>

Try the test I suggested in my last post first.

---

<div class="post-metadata">

**Author:** ![EliteCanadian](https://avatars.discourse-cdn.com/v4/letter/e/3d9bf3/32.png) [@EliteCanadian](https://staging-discuss.dev.twitch.com/u/EliteCanadian)\
**Post date:** [June 27, 2013, 6:01am UTC](https://staging-discuss.dev.twitch.com/t/creating-an-irc-bot/41/8 "2013-06-27T06:01:20Z")

</div>

My friend helped me fix this, thanks!

---

<div class="post-metadata">

**Author:** ![Kantenkugel](https://avatars.discourse-cdn.com/v4/letter/k/46a35a/32.png) [@Kantenkugel](https://staging-discuss.dev.twitch.com/u/Kantenkugel)\
**Post date:** [August 21, 2013, 7:52pm UTC](https://staging-discuss.dev.twitch.com/t/creating-an-irc-bot/41/9 "2013-08-21T19:52:52Z")

</div>

Hey nice to see that you could solve the problem. Would you mind sharing us your solution?  
I have the same problem and cant get it to work ☹

---

<div class="post-metadata">

**Author:** ![Kantenkugel](https://avatars.discourse-cdn.com/v4/letter/k/46a35a/32.png) [@Kantenkugel](https://staging-discuss.dev.twitch.com/u/Kantenkugel)\
**Post date:** [August 21, 2013, 8:33pm UTC](https://staging-discuss.dev.twitch.com/t/creating-an-irc-bot/41/10 "2013-08-21T20:33:02Z")

</div>

Ah i figured it out now too. Pircbot will not update the isOp for me so i overwrote the onUserMode(String, String, String, String mode) method (standard implementation does nothing) and made it add/remove the user to/from a Set. This solution worked for me finally.  
Btw: the String mode of onUserMode(…) contains following: “#Channel +o user” (or -o if moderator status was removed)

---

<div class="post-metadata">

**Author:** ![proboards7](https://avatars.discourse-cdn.com/v4/letter/p/a9a28c/32.png) [@proboards7](https://staging-discuss.dev.twitch.com/u/proboards7)\
**Post date:** [April 29, 2014, 9:47pm UTC](https://staging-discuss.dev.twitch.com/t/creating-an-irc-bot/41/11 "2014-04-29T21:47:41Z")

</div>

I use a mIRC bot for twitch and the command i use there to make a vieuwer moderator = `.Moderator: say /mod $$1 | say Hello $$1 you have now added to the Moderators.`  
Natuurlijk als je op twitch life stream wil komen met je bot als moet je die bot moderator maken via the live feed host `/mod (username)`  
If your in your bot channel then you have to register a bot name on twitch it self.

---

<div class="post-metadata">

**Author:** ![subitoit](https://avatars.discourse-cdn.com/v4/letter/s/b3f665/32.png) [@subitoit](https://staging-discuss.dev.twitch.com/u/subitoit)\
**Post date:** [May 5, 2014, 1:27pm UTC](https://staging-discuss.dev.twitch.com/t/creating-an-irc-bot/41/12 "2014-05-05T13:27:01Z")

</div>

Do you think if I personal message you my code, you can check it out?
