I've got a Discord Python bot where I'm attempting to run a background task that will send a message to a channel every X seconds constantly - no command required. Currently have an arbitrary 5 seconds for testing purposes.
Here's the cog file in question (imports and whatnot removed for efficiency)
class TestCog(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.mytask.start()
@tasks.loop(seconds=5.0)
async def mytask(self):
channel = client.get_channel(my channel id here)
await channel.send("Test")
def setup(bot):
bot.add_cog(TestCog(bot))
I've got a feeling this is due to the self parameter being the only passed argument, but I'm a little confused reading the API documentation on what exactly to do here.
I've tried client instead of bot, I've tried defining discord.Client() (but as far as what I've read, I shouldn't use that which I've been trying to avoid.
In other cogs which use actual commands, I have it setup like this which works:
@commands.command(name='test')
async def check(self, ctx):
if ctx.channel.name == 'channel name':
await ctx.send("Response message")
This is what led me to believe the parameter(s) I'm passing are wrong. I understand because I'm passing ctx I can grab the channel name, but I'm not too sure how to do this with just self. When attempting to pass the ctx parameter I don't get any errors, but the messages do not send for obvious reasons.
What exactly am I missing here? I appreciate any help!