简体   繁体   中英

Discord.py can't find channel by correct channel ID

I'm trying to add a functionality to my discord bot to send a certain message every 10 seconds (content of the message is not important right now). Here's my code:

@client.event
async def on_ready():
    await client.wait_until_ready()
    await client.loop.create_task(update_task())

async def update_task():
    await client.wait_until_ready()

    chn = client.get_channel('#')
    while True:

        await chn.send('message')
        await asyncio.sleep(10)

and I get the error:

AttributeError: 'NoneType' object has no attribute 'send'

I've seen couple of similar questions already and all of the solutions are to add

await client.wait_until_ready()

before, but this doesn't work for me and I still get the error. Does anyone have a clue on how to fix this?

This isn't working because get_channel() requires an int type object that equals an id belonging to a channel the bot can access. For example, this would be a correct usage: channel = client.get_channel(700437301263728720)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM