首页 > 解决方案 > 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 对象,而不是“成员”

似乎大多数这些错误都与它试图调用的模块或其他文件有关,我只是无法弄清楚如何修复它们。

标签: pythondiscorddiscord.py

解决方案


尝试 str(message.author) 看起来您正在尝试将 2 个东西连接在一起,其中一个不是字符串。


推荐阅读