Custom Commands for Different Streamers #424
-
Hello! I want to start making my own twitch Chatbot, now i started making a database for user's custom commands, now how to make the custom commands in my Python Bot? For example: I want to add a custom command to my stream (for example !lurk) and a friend of mine dont want this command, but have his own custom command for example !greetings import json
import mysql.connector
from twitchio.ext import commands
connection = mysql.connector.connect(host="", user="", password="", database="")
cursor = connection.cursor()
# Insert data into the table
cursor.execute("SELECT * FROM users")
users = cursor.fetchall()
connection.commit()
connection.close()
class Bot(commands.Bot):
def __init__(self):
super().__init__(
token="", prefix="!", initial_channels=[user[0] for user in users]
)
for user in users:
try:
user_name = user[0]
user_id = user[1]
user_json = user[2]
custom_commands_json = json.loads(user_json)
except:
pass
async def event_ready(self):
print(f"Logged in as | {self.nick}")
print(f"User id is | {self.user_id}")
bot = Bot()
if __name__ == "__main__":
bot.run() |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Firstly, do not use mysql.connector as it is not async and can block the event loop / bot. Second using an async lib like aiomysql (although postgres is a superior database) should allow up to return commands with a DictCursor negating the need to load into json. Third you would have to constantly check every message in event_message for the prefix and the key in your dict for which would be a nested key to the streamer name. |
Beta Was this translation helpful? Give feedback.
Firstly, do not use mysql.connector as it is not async and can block the event loop / bot.
Second using an async lib like aiomysql (although postgres is a superior database) should allow up to return commands with a DictCursor negating the need to load into json.
Third you would have to constantly check every message in event_message for the prefix and the key in your dict for which would be a nested key to the streamer name.