You're getting None
because the client's cache isn't loaded in yet.
I'd also recommend using commands.Bot(...)
as opposed to discord.Client()
if you're planning on adding commands later. commands.Bot()
inherits Client()
, so anything you can do right now, you'll also be able to do with Bot()
.
To fix this, you can get the user in the on_ready
event:
@tasks.loop(minutes=1)
async def test(channel):
await channel.send("test")
@bot.event
async def on_ready()
channel = bot.get_channel(ID_HERE)
test.start(channel=channel)
If you're still getting None
, you need to enable privileged intents. This can be done by the following code, and enabling the following button in your application page:
intents = discord.Intents().all()
bot = commands.Bot(command_prefix=..., intents=intents)
References:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…