python - Bot Discord Python:自动发送消息的问题
问题描述
我的目标是创建一个 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)
预先感谢您的帮助 !
解决方案
而不是client.send
你可以直接使用通道使用channel.send
方法!
async def job():
channel = client.get_channel(ID)
message = "Hello !"
await channel.send(message)
# rest of your code here.
参考文献:
推荐阅读
- c# - 我如何在 Selenium 和 C# 中使用点击事件
- javascript - 使用特定的 smoot-scroll 库将类添加到 Anchor
- security - 允许移动互联网在 AWS EC2 实例中进行 ssh
- arduino - 在 arduino 上激活 ISR 的覆盆子 GPIO 引脚
- javascript - 如何正确划分不同页面的javascript逻辑?
- android - 如何在android中重置GTM数据层?
- ios - 使用 swift 在不使用自动尺寸的情况下获取 tableView 中动态文本视图的高度
- google-maps - 寻找地图点的最佳街道
- mongo-java - MongoAuthority 中的 type=Direct 是什么
- algorithm - 设计一个服务来计算过去 24 小时内听过的前 k 首歌曲