我的目标是创建一个 Discord 机器人,在特定时间和日期向房间发送消息。不幸的是,我遇到了一个问题,我的 python 机器人声明了两个错误:Task exception was never retrieved future: <Task finished name = 'Task-1' coro = <job () done"
和 "await client.send (message, channel) AttributeError: 'Client' object has no attribute 'send' AttributeError: 'Client' object has no attribute 'send'
,尽管它启动了,但机器人没有发送所需的消息。
这是我的代码:
bot = commands.Bot(command_prefix='!')
client = discord.Client()
@bot.event
async def on_ready():
print("Hello !")
@bot.event
async def job():
channel = client.get_channel(ID)
message = ('Hello !')
await client.send(message, channel)
sched = BlockingScheduler()
sched.add_job(job, 'cron', month='1-12', day_of_week='mon-sun', hour='0-23')
sched.start()
client.loop.create_task(job())
bot.run(TOKEN)
预先感谢您的帮助!
答案 0 :(得分:0)
您可以使用 client.send
方法直接使用频道,而不是 channel.send
!
async def job():
channel = client.get_channel(ID)
message = "Hello !"
await channel.send(message)
# rest of your code here.
参考: