我正在尝试使漫游器每分钟在discord.py中发送一条消息。我确实承认这是一件容易的事,但是我已经尝试了很多次,但是都没有运气。我还没有收到任何错误消息。
这是我的代码:
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)
答案 0 :(得分:2)
您尝试使用get_channel()
获取频道,但您的漫游器尚未准备就绪。因此,您得到NoneType
对象,而不是通道对象。尝试此解决方案:
@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()