Queen Valkyrie 🥭
Queen Valkyrie 🥭
RRailway
Created by Queen Valkyrie 🥭 on 10/8/2024 in #✋|help
Name error SQL table python
I'm encountering a NameError indicating that guild_id is not defined during the insertion process. I have the following code for creating the schedules table: cursor.execute(''' CREATE TABLE IF NOT EXISTS schedules ( guild_id BIGINT PRIMARY KEY, channel_id BIGINT NOT NULL, hour INT NOT NULL, minute INT NOT NULL, timezone VARCHAR(50) NOT NULL, frequency ENUM('daily', '2-daily', 'weekly') NOT NULL ) ''') A and this for the callback:*( async def schedule_callback(interaction, frequency, hour, minute, timezone): await interaction.response.defer()
ctx = interaction.channel guild_id = interaction.guild.id
insert** connection = create_connection() cursor = connection.cursor() cursor.execute(''' INSERT INTO schedules (guild_id, channel_id, hour, minute, timezone, frequency) VALUES (%s, %s, %s, %s, %s, %s) ON DUPLICATE KEY UPDATE guild_id = VALUES(guild_id), # Adding guild_id here channel_id = VALUES(channel_id), hour = VALUES(hour), minute = VALUES(minute), timezone = VALUES(timezone), frequency = VALUES(frequency) ''', (guild_id, channel_id, hour, minute, timezone, frequency)) connection.commit() cursor.close() connection.close()
6 replies
RRailway
Created by Queen Valkyrie 🥭 on 10/8/2024 in #✋|help
Python code can't connect to MySQL railway
Does anyone have any experience with creating a scheduling bot? I want a bot that posts facts in a set schedule. All this isn't an issue, I got that The issue is when the bot goes offline for a few seconds the schedule is lost. So I tried to put the schedule in a SQL database I use Github and Railway, However I can't seem to properly connect to MySQL database in railway. I checked the variables about 20times now I even deleted everything and started over, but still I can't manage to connect. I am a beginner so I think I'm missing something, overlooking something I just have no idea what. If anyone has any advice I would love to hear it 🙂
33 replies