[英]Sending message every minute in discord.py
I am trying to make the bot send a message every minute in discord.py.我试图让机器人在 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)
You try to get channel with get_channel()
, but your bot is not ready yet.您尝试使用
get_channel()
获取频道,但您的机器人尚未准备好。 So you get NoneType
object, not channel.所以你得到
NoneType
object,而不是通道。 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()
yes but it cant send the message because it has no ctx是的,但它无法发送消息,因为它没有 ctx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.