python - Discord.Py 没有在 Discord 中发送我的消息
问题描述
我希望我的机器人根据今天是哪一天说出某行代码。但是,这会导致问题,因为该机器人甚至没有在 Discord 中编写任何内容。
async def schedule(ctx):
if x.strftime == "Wednesday":
await ctx.send(f""" Today is {x.strftime}. Today is a half day.
Today's Schedule:
Block 1: 7:25 - 8:25
Block 2: 8:30 - 9:30
Block 3: 9:35 - 10:35
Block 4: 10:40 - 11:40""")
elif x.strftime == "Monday" or x.strftime == "Tuesday" or x.strftime == "Thursday" or x.strftime == "Friday":
await ctx.send(f""" Today is {x.strftime}. Today is a full day.
Today's Schedule:
Block 1: 7:25 - 8:50
Block 2: 8:55 - 10:15
Block 3: 10:20 - 12:25
Block 4: 12:33 - 1:55""")
elif x.strftime == "Saturday" or x.strftime == "Sunday":
await ctx.send(f"Today is {x.strftime}. No school today.")
解决方案
from datetime import datetime
@client.command() # Change client to whatever you're using
async def schedule(ctx):
day = datetime.now().strftime("%A")
if day == "Wednesday":
await ctx.send(f"Today is {day}. Today is a half day.\n**Today's Schedule**"
f"Block 1: 7:25 - 8:25\nBlock 2: 8:30 - 9:30\nBlock 3: 9:35 - 10:35\n"
f"Block 4: 10:40 - 11:40")
elif day == "Saturday" or day == "Sunday":
await ctx.send(f"Today is {day}. No school today.")
else:
await ctx.send(f"Today is {day}. Today is a full day.\n**Today's Schedule**\n"
f"Block 1: 7:25 - 8:50\nBlock 2: 8:55 - 10:15\nBlock 3: 10:20 - 12:25\nBlock 4: 12:33 - 1:55")
推荐阅读
- android - 有没有办法让 android studio(调试签名)同时在办公室和家庭办公室工作?
- r - 使用 r 按条件分组
- postgresql - PostgreSQL 空闲进程
- python - Django原子事务处理唯一约束
- python - 在 Python 中创建一个包含两个变量的循环,其中一个变量仅在每第 n 个循环后更改,而另一个变量随每个循环更改
- php - Laravel 中的资源控制器概念
- c# - 如何在不破坏代码的情况下实现无限循环?
- spring-boot - Spring Boot 微服务依赖
- r - 在 SparklyR 中使用日期时间列的星期几列
- git - 无法使用 Jenkins 对 git repo 中提交的代码执行 TestNG.xml