I’m working on a simple Discord Bot with Python. I just want to save guild id on a SQLite folder, I can’t get guild id. I’m new on that database things. Parameters on event doesn’t work like:
@bot.event async def on_guild_join(ctx): dbase = sqlite3.connect('dbase.sqlite') cursor = dbase.cursor() cursor.execute('CREATE TABLE IF NOT EXISTS data(guild_id TEXT)') cursor.execute(f'INSERT INTO data (guild_id) VALUES ({ctx.guild.id})')
Advertisement
Answer
on_guild_join only has the parameter of Guild and not Context.
@bot.event async def on_guild_join(guild): dbase = sqlite3.connect('dbase.sqlite') cursor = dbase.cursor() cursor.execute('CREATE TABLE IF NOT EXISTS data(guild_id TEXT)') cursor.execute(f'INSERT INTO data (guild_id) VALUES ({guild.id})')