python - Python/Discord——我正在制作一个不和谐的机器人,但 os 模块存在一些问题:
问题描述
这是我添加时导致错误的代码:
如果 message.content == "ID 开始":
dir=(r'C:\\Users\\User\Desktop\User Profiles')
file = message.author
path = os.path.join(dir,file)
isExist = os.path.exists(path)
if isExist == True:
await message.channel.send("You already have a profile")
这是错误消息:
忽略 on_message Traceback 中的异常(最后一次调用):文件“C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py”,第 312 行,_run_event 等待coro(*args, **kwargs) 文件“C:/Users/User/Desktop/idlerpgtest.py”,第 31 行,on_message 路径 = os.path.join(dir,file) 文件“C:\Users\User \AppData\Local\Programs\Python\Python38\lib\ntpath.py",第 117 行,加入 genericpath._check_arg_types('join', path, *paths) 文件“C:\Users\User\AppData\Local\Programs \Python\Python38\lib\genericpath.py", line 152, in _check_arg_types raise TypeError(f'{funcname}() argument must be str, bytes, or ' TypeError: join() argument must be str, bytes, or os .PathLike 对象,而不是“成员”
似乎大多数这些错误都与它试图调用的模块或其他文件有关,我只是无法弄清楚如何修复它们。
解决方案
尝试 str(message.author) 看起来您正在尝试将 2 个东西连接在一起,其中一个不是字符串。
推荐阅读
- javascript - 如何在执行其余代码之前等待图像下载
- sql - 为什么不执行此 Azure SQL 存储过程?
- google-apps-script - Google Apps 脚本 - 基于时间的触发器
- html - 使用引导程序 4 排列 DIV 而不使用额外的 DIV
- objective-c - 如何在从 Objective-C 迁移到 Swift 时正确地将使用 NSKeyedArchiver 保存的旧数据迁移到新格式
- google-app-engine - 如何在 Gradle 中为 appengineRun 使用 jvmFlags 中的 projectDir?
- jestjs - 如何用 jest 测试减速器
- python - 如何替换在python中随机选择和删除的列表中的元素?
- https - 如何保护到服务器的发布请求有效负载?
- azure - Azure Application Insights 在从一个订阅移动到另一个订阅时保留日志数据?