#Send message to specific guild-channel from extension task?

1 messages · Page 1 of 1 (latest)

opaque blazeBOT
#

Hey! Once your issue is solved, press the button below to close this thread!

pastel pulsar
#

Get the channel from the guild and send it there

sullen moss
#

you do probably want to use get/fetch_channel

#

(depending on how your cache is set up, either one could work)

#

if it errors out... that probably suggest other things are going wrong

rotund scaffold
#

@ornate ember

  1. You will need some way of storing data outside of the loop like you say. I'd recommend some sort of disk storage (like a database, or even JSON depending on your scalability needs). If you store the data in memory only (like a Python dictionary), you won't know whether you've posted a message once the bot restarts. This is unrelated to the library though, and is just general Python.

  2. Your method for having a repeating task works, but I don't see why you'd do that over ipy's tasks implementation. I may be mistaken, though I think ipy's tasks do have proper error handling, scheduling and are more flexible.

rotund scaffold
#

SQLite would be a good shout :)

sullen moss
#

sqlite is great for small bots, yeah

#

postgres is always a good option, and mysql... certainly is an option too (i have my opinions)
regardless, once you know one, you know the others decently well

rotund scaffold
#

I'm not sure why your code isn't reaching your ctx.send part, but you should make sure you close the db connection.
aiosqlite recommends using a context manager async with... or you should use a try, finally to make sure the connection closes.

Regarding your issue: You're executing using a cursor object. I'm not 100% sure whether that would work. Aiosqlite's documentation uses the db connection to execute, and then the cursor to fetch data.

#

Yeah sorry for the confusion with the message edit. I don't think there is a problem with where your db.commit is.
That error message is saying.. well, exactly what it says. That database is locked and cannot be edited. This is probably because you never closed the connection.

rotund scaffold
#

If you look at your ctx.send and the guild_channel, you'll notice you're trying to send an object. In the docs, the channel object has a .mention, so guild_channel.mention should be your fix 😄