SingleServerIRCBot - TwitchBot doesn't work with commands like /ban
Archived 3 years ago
F
Flyvs
Hello, I'm working on a TwitchBot that should be able to use / commands like /ban (or .ban). It responds to stuff like !test. However it doesn't seem to like / commands. I have found nothing except "Has your bot permissions? Is the token correct?" This does not help me since it has all of the permissions it needs.
I also tried to use connection.send_raw() or connection.privmsg(). The privmsg() thingy works for normal responses so I thought it would for /ban etc. too but it doesn't.
Idk if I misunderstood something when sending / commands but I assumed I could send /ban <username> the same way as a normal response.
Heres the code that gets executed as soon as a message appears in chat:
```def on_pubmsg(self, connection, event):
message = Message(event.arguments[0])
with open(self.commandFile, "r") as c:
commands = c.readlines()
if message.message.startswith("!"):
for command in commands:
command = command.rstrip("\n")
cmd = command.split(";")[1].rstrip(" ")
if cmd == message.message.split(" ")[0].lstrip("!"):
if cmd == "add":
prefix, cmd, response = message.message.split(" ")[1][0], message.message.split(" ")[1][1:], message.message.split(" ")[2]
newCommand = "{};{};{}".format(prefix, cmd, response)
if newCommand in commands:
self.msg = 'Command: "{}{}" --> "{}" already exists!'.format(prefix, cmd, response)
else:
self.addCommand(newCommand)
self.msg = 'Command: "{}{}" --> "{}" was successfully added!'.format(prefix, cmd, response)
elif cmd == "play":
sound = message.message.split(" ")[1]
try:
self.playSound(sound)
self.msg = 'Played sound "{}"'.format(sound)
except:
self.msg = 'An error occurred while trying to play: "{}"'.format(sound)
else:
self.msg = command.split(";")[2]
Message.send(self, self.msg, self.channel)
break
elif self.randomBanWord.casefold() in message.message.casefold():
self.ban(<username>) # didn't implement the getUser function yet so I just enter the username manually for testing
def ban(self, username):
Message.send(self, "Entered ban function with username: {}".format(username), self.channel)
self.connection.send_raw(f"PRIVMSG #{self.channel} :/ban {username}")```
And here is the Message class:
```class Message():
def __init__(self, message: str):
self.message = message
def send(self, message: str, channel: str):
self.connection.privmsg(channel, message)```
It feels like my bot doesn't have permissions for banning or using other / commands even though it has *every* permission I could give it...
ChatGPT also only tells me stuff I already know. I have no clue what to do at this point. Should I switch to `pytwitchapi`? However I never really understood async functions so I used the IRCBot.
Ping me please if you respond (Unless the post pings me automatically when someone responds; I have no clue how the posts work).
You can answer in English or in German.
Any kind of help is appreciated!
