Sending message every minute in discord.py

巧了我就是萌 提交于 2021-02-05 09:44:44

问题


I am trying to make the bot send a message every minute in discord.py. I do acknowledge that this is a easy thing to do but I have tried multiple times but resulting with no luck. I have not gotten any error messages.

Here is my code:

import discord
from discord.ext import tasks

client = discord.Client()

@tasks.loop(minutes=1)
async def test():
    channel = client.get_channel(CHANNEL_ID)
    channel.send("test")

test.start()

client.run(TOKEN)

回答1:


You try to get channel with get_channel(), but your bot is not ready yet. So you get NoneType object, not channel. Try to this solution:

@tasks.loop(minutes=1)
async def test():
    channel = client.get_channel(CHANNEL_ID)
    await channel.send("test")

@client.event
async def on_ready():
    test.start()


来源:https://stackoverflow.com/questions/62569111/sending-message-every-minute-in-discord-py

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!